1 /* $.post $.get 请求header增加csrf token */
2 $.each(["get", "post"], function (i, method) {
3 $[method] = function (url, data, callback, type) {
4 if ($.isFunction(data)) {
5 type = type || callback;
6 callback = data;
7 data = undefined;
8 }
9 return $.ajax({
10 url: url,
11 type: method,
12 dataType: 'json',
13 headers: {'X-CSRF-TOKEN': '{{ csrf_token() }}'},
14 contentType: 'application/json',
15 data: JSON.stringify(data),
16 success: callback,
17 beforeSend: function (xhr) {
18 xhr.setRequestHeader("X-CSRF-TOKEN", '{{ csrf_token() }}');
19 }
20 });
21 };
22 });