Skip to content

Instantly share code, notes, and snippets.

@justinperkins
Created October 26, 2012 17:48
Show Gist options
  • Star 20 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save justinperkins/3960219 to your computer and use it in GitHub Desktop.
Save justinperkins/3960219 to your computer and use it in GitHub Desktop.
Put auth-token on all jQuery Ajax Requests
$(function(){
var tokenValue = $("meta[name='csrf-token']").attr('content');
$.ajaxSetup({
headers: {'X-CSRF-Token': tokenValue}
});
})
@davifiamenghi
Copy link

@ses4j: I think that would be undesirable to expose the authorization header on a $.get to a third part resource (for example images)

@marcin-krysiak
Copy link

This might be of your interest. This code extends jQuery Ajax to include token to the defined ajax requests types that was previously get from your server.

I successfully use that code in many projects

the url is here: https://github.com/marcinkrysiak1979/jquery-ajax-addToken

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment