Reputation: 341
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') {
...
}
}
Upvotes: 4
Views: 2105
Reputation: 3374
Well, I thought this was a valid question and came across this when trying to solve the problem myself.
You can use the this
context. I'm using the url property, but there are a few others.
Here's an example of what solved my problem. (Note that I have control over the AJAX calling code, but not the server-side code, which is where the "bIDold" should be returned from.)
$.post(url, obj, function(data) {
var bIDold = this.url.match(/bID=(\d*)/)[1];
var bIDnew = data.bID;
if (bIDold != bIDnew) { ... }
});
Yours would be something like:
if (this.url.match(/A=([^&]*)/)[1] == 'B') { ...
Upvotes: 1
Reputation: 104168
Use the beforeSend method to view the XMLHttpRequest object or modify it.
Upvotes: 0
Reputation: 7374
Firebug:
If you want more detailed information and you're using PHP you can also use FirePHP for server debugging of ajax requests.
Upvotes: 2