Skip to content

Instantly share code, notes, and snippets.

@brandonaaron
Created January 12, 2009 16:52
Show Gist options
  • Save brandonaaron/46052 to your computer and use it in GitHub Desktop.
Save brandonaaron/46052 to your computer and use it in GitHub Desktop.
$(document).ajaxSend(function(event, request, settings) {
// pass authenticity token with requests
// requires global AUTH_TOKEN var to be set by Rails:
// <%= javascript_tag "var AUTH_TOKEN = #{form_authenticity_token.inspect};" if protect_against_forgery? %>
settings.data = (settings.data ? settings.data + "&" : "") + "authenticity_token=" + encodeURIComponent( AUTH_TOKEN );
// make respond_to jump to the js block
if ( settings.dataType == 'html' ) request.setRequestHeader("Accept", "text/javascript");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment