jQuery:
1 2 3 4 5 |
$.ajaxPrefilter(function(options, originalOptions, jqXHR) { var token = $("meta[name='_csrf']").attr("content"); var header = $("meta[name='_csrf_header']").attr("content"); jqXHR.setRequestHeader(header, token); }); |
Angular:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
angular.module("app", []) .controller("MyController", ['$http', function ($http) { // ... $http.get("/foo").success(function(data) { // ... }); }]) .config([ "$httpProvider", function($httpProvider) { var token = $("meta[name='_csrf']").attr("content"); var header = $("meta[name='_csrf_header']").attr("content"); $httpProvider.defaults.headers.common[header] = token; }]); |
Für die CSRF-Token siehe hier.