Skip to content

Instantly share code, notes, and snippets.

@asifkhankadiwala
Forked from 0xnbk/ajax.setup.js
Created April 23, 2018 09:04
Show Gist options
  • Select an option

  • Save asifkhankadiwala/fb329327cc7f6987ddcf1582a23014ba to your computer and use it in GitHub Desktop.

Select an option

Save asifkhankadiwala/fb329327cc7f6987ddcf1582a23014ba to your computer and use it in GitHub Desktop.
// app.js
$.ajaxSetup({
// force ajax call on all browsers
cache: false,
// Enables cross domain requests
crossDomain: true,
// Helps in setting cookie
xhrFields: {
withCredentials: true
},
beforeSend: function (xhr, type) {
// Set the CSRF Token in the header for security
if (type.type !== "GET") {
var token = Cookies.get("XSRF-TOKEN");
xhr.setRequestHeader('X-XSRF-Token', token);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment