Skip to content
This repository has been archived by the owner on Mar 29, 2019. It is now read-only.

Commit

Permalink
Set the X-CSRF-Token header for AJAX requests with jQuery. #950
Browse files Browse the repository at this point in the history
  • Loading branch information
EspadaV8 authored and thegcat committed May 20, 2012
1 parent 375045a commit 61c0077
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion public/javascripts/application.js
Expand Up @@ -467,7 +467,15 @@ jQuery.viewportHeight = function() {

// Automatically use format.js for jQuery Ajax
jQuery.ajaxSetup({
'beforeSend': function(xhr) {xhr.setRequestHeader("Accept", "text/javascript")}
'beforeSend': function(xhr) {
xhr.setRequestHeader("Accept", "text/javascript");

// TODO: Remove once jquery-rails (Rails 3) has been added a dependency
var csrf_meta_tag = jQuery('meta[name="csrf-token"]');
if (csrf_meta_tag) {
xhr.setRequestHeader('X-CSRF-Token', csrf_meta_tag.attr('content'));
}
}
})

/* TODO: integrate with existing code and/or refactor */
Expand Down

0 comments on commit 61c0077

Please sign in to comment.