Skip to content

Instantly share code, notes, and snippets.

@kmdsbng
Created September 27, 2014 10:54
Show Gist options
  • Select an option

  • Save kmdsbng/e036ee01afd46e00506d to your computer and use it in GitHub Desktop.

Select an option

Save kmdsbng/e036ee01afd46e00506d to your computer and use it in GitHub Desktop.
$.ajaxSetup({
beforeSend: function(xhr, settings) {
if (settings.type == 'POST' || settings.type == 'PUT' || settings.type == 'DELETE') {
if (!(/^http:.*/.test(settings.url) || /^https:.*/.test(settings.url))) {
// Only send the token to relative URLs i.e. locally.
xhr.setRequestHeader("X-CSRF-Token", $('meta[name="csrf-token"]').attr('content'));
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment