Created
February 21, 2014 20:13
-
-
Save joefiorini/9142498 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.ajaxPrefilter(function(options, originalOptions, jqXHR) { | |
var token; | |
if (!options.crossDomain) { | |
token = $('meta[name="csrf-token"]').attr('content'); | |
if (token) { | |
return jqXHR.setRequestHeader('X-CSRF-Token', token); | |
} | |
} | |
}); | |
$(document).on("ajaxComplete", function(event, xhr, settings) { | |
var csrf_param = xhr.getResponseHeader('X-CSRF-Param'); | |
var csrf_token = xhr.getResponseHeader('X-CSRF-Token'); | |
if (csrf_param) { | |
$('meta[name="csrf-param"]').attr('content', csrf_param); | |
} | |
if (csrf_token) { | |
$('meta[name="csrf-token"]').attr('content', csrf_token); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment