I’m writing a JS script that lives within a system which is now adding a custom XID header to all Ajax requests via jqXHR.setRequestHeader() in a function registered with jQuery.ajaxPrefilter().
In my script, I need to make an Ajax request to a third party site, whose Access-Control-Allow-Headers is not set up to allow this custom XID header.
It seems I have 3 options:
- Find a way to remove that XID header in $.ajax()’s beforeSend function, which I have confirmed gets called after the ajaxPrefilter() function.
- Forgo using $.ajax() entirely and just write the Ajax stuff myself.
- Have $.ajax() point to the system’s backend which does accept the custom XID header, and perform the request to the third party site via cURL.
Option #1 is preferred, if there’s a simple way to do it, since it will be the cleanest and fastest route. Just can’t figure out how.
I have tried overriding it like this, but it didn’t work:
beforeSend: function(jqXHR, settings) {
jqXHR.setRequestHeader('custom-xid-header', null);
}
Any ideas?