Skip to content

Instantly share code, notes, and snippets.

@0xnbk
Created September 2, 2015 05:31
Show Gist options
  • Save 0xnbk/45934f5fa7d56830656c to your computer and use it in GitHub Desktop.
Save 0xnbk/45934f5fa7d56830656c 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