views:

64

answers:

3

I am making an AJAX request via jQuery's $.ajax() method.

I have specified a success callback using :

$.ajax({
    ...
    success: function(data, textStatus, xhr) {
        ...
    }
});

Is it possible to see in the callback what request headers were sent ? For example, to retrieve a specific request header value ?

EDIT: The requirement is that I do not "own" the code calling the AJAX request, only the callback. I need to check in the callback whether a specific header was passed.

e.g.

in their code is :

$.ajax({
    beforeSend: function(xhr) {
            xhr.setRequestHeader('A','B');
    },
    success: rogersCallbackMethod
});

Then in my code I would like to say something like this :

function rogersCallbackMethod(data, textStatus, xhr) {
    if (xhr.getRequestHeader('A') == 'B') {
           ...
    }
}
+2  A: 

Firebug:

http://getfirebug.com/

If you want more detailed information and you're using PHP you can also use FirePHP for server debugging of ajax requests.

http://www.firephp.org/

Alex
A: 

Use the beforeSend method to view the XMLHttpRequest object or modify it.

kgiannakakis
A: 

Check out Fiddler. It works in IE and Firefox.

Sander Pham