Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hayatbiralem/323418d3d0acda141496fe7cee83ddde to your computer and use it in GitHub Desktop.
Save hayatbiralem/323418d3d0acda141496fe7cee83ddde to your computer and use it in GitHub Desktop.
Remove Default jQuery Ajax Header
$.ajax(
'https://api.github.com/search/repositories?q=' + encodeURIComponent(search),
{
// 'xhr' option overrides jQuery's default
// factory for the XMLHttpRequest object.
// Use either in global settings or individual call as shown here.
xhr: function() {
// Get new xhr object using default factory
var xhr = $.ajaxSettings.xhr();
// Copy the browser's native setRequestHeader method
var setRequestHeader = xhr.setRequestHeader;
// Replace with a wrapper
xhr.setRequestHeader = function(name, value) {
// Ignore the X-Requested-With header
if (name == 'X-CSRF-TOKEN') return;
// Otherwise call the native setRequestHeader method
// Note: setRequestHeader requires its 'this' to be the xhr object,
// which is what 'this' is here when executed.
setRequestHeader.call(this, name, value);
};
// pass it on to jQuery
return xhr;
}
}
)
.done(
function (res) {
console.log(res);
vm.clients = res.items;
}
)
.always(
function () {
loading(false);
}
)
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment