Laravel框架在执行ajax请求时附带token
分类:Javascript, Others, PHP
阅读 (490)
7月 042020
代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<script> function updateHomeSummary(){ $.ajaxSetup({ headers: { 'X-CSRF-TOKEN' : '{{ csrf_token() }}' } }); $.ajax({ type: "POST", url: "homedatasummary", dataType: "json", success: function (data) { }, error: function(XMLHttpRequest, textStatus, errorThrown) { } }); } </script> |
其中,ajax前面这段代码是用来附加token的
$.ajaxSetup({ headers: { ‘X-CSRF-TOKEN’ : ‘{{ csrf_token() }}’ } });
Sorry, the comment form is closed at this time.