I setup some custom headers using
$.ajaxSetup({
headers : {
'x-custom' : 'value'
}
});
It will addx-custom
header for all the ajax request. But I want some specific requests to NOT contain this header.
I tried this, delete header from ajaxSettings before that ajax call and add it back when its completed
delete $.ajaxSettings.headers["x-custom"];
$.ajax({
...
"success": function (data) {
$.ajaxSettings.headers["x-custom"] = 'value';
...
}
});
But I feel this is not the correct way, as the request that fired before finishing that call will not get that header. What else can I do please suggest.
Should I add the header back in the next line after $.ajax
instead doing it in callback?
delete $.ajaxSettings.headers["x-custom"]; $.ajax(...); $.ajaxSettings.headers["x-custom"] = 'value';
– Arun P Johny Apr 30 '14 at 9:30delete $.ajaxSettings.headers["x-custom"];
did the trick for me. I am using it now. – Jason Kim Aug 7 '14 at 18:29