Laravel通过Ajax调用和AWS负载均衡器丢失了CSRF令牌

时间:2017-06-21 22:02:11

标签: php ajax amazon-web-services laravel-5 amazon-ec2

由于我将Laravel 5.4项目移至AWS,因此大多数Ajax请求都会抛出错误$( document ).ready(function() { var data; $.getJSON('data.json', function (d) { data = d; console.log('data', d); setupDatepickers(); }); function setupDatepickers() { // use ajax data mapped to same structure as original variables var firstDate = flattenFieldsArray(data.firstDate); var lastDate = flattenFieldsArray(data.lastDate); var availabledays = flattenFieldsArray(data.availabledays); var booked = flattenFieldsArray(data.booked);; var ssdays = []; // nothing was changed below var dateFormat = "mm/dd/yy", from = $("#checkin") .datepicker({ beforeShowDay : function (date) { var y = date .getFullYear() .toString(); // get full year var m = (date.getMonth() + 1).toString(); // get month. var d = date .getDate() .toString(); // get Day if (m.length == 1) { m = '0' + m; } // append zero(0) if single digit if (d.length == 1) { d = '0' + d; } // append zero(0) if single digit var currDate = y + '-' + m + '-' + d; if (jQuery.inArray(currDate, availabledays) >= 0) { return [false, "ui-highlight"]; } if (jQuery.inArray(currDate, booked) >= 0) { return [true, "ui-bos"]; } else { return [true]; } }, changeMonth : true, firstDay : 1, isTo1 : true, maxDate : new Date(lastDate), minDate : new Date(firstDate), numberOfMonths: 2, onSelect : function (selectedDate) { var yenitarih = new Date(); var date = $(this).datepicker('getDate'); date.setTime(date.getTime() + (1000 * 60 * 60 * 24)) $("#checkout").datepicker("option", "minDate", date); } }) .on("change", function () { to.datepicker("option", "minDate", getDate(this)); }), to = $("#checkout") .datepicker({ beforeShowDay : function (date) { var y = date .getFullYear() .toString(); // get full year var m = (date.getMonth() + 1).toString(); // get month. var d = date .getDate() .toString(); // get Day if (m.length == 1) { m = '0' + m; } // append zero(0) if single digit if (d.length == 1) { d = '0' + d; } // append zero(0) if single digit var currDate = y + '-' + m + '-' + d; if (jQuery.inArray(currDate, booked) >= 0) { return [true, "ui-highlight-donus"]; } if (jQuery.inArray(currDate, availabledays) >= 0) { return [true, "ui-bos"]; } if (jQuery.inArray(currDate, ssdays) >= 0) { return [true, "ui-ss-donus"]; } else { return [true]; } }, changeMonth : true, changeYear : true, firstDay : 1, maxDate : new Date(lastDate), minDate : new Date(firstDate), numberOfMonths: 2, onSelect : function (selectedDate) { $("#checkin").datepicker("option", "maxDate", selectedDate); } }) .on("change", function () { from.datepicker("option", "maxDate", getDate(this)); }); } }); 。我不知道还能做些什么来解决它。另一个可能很重要的信息是我在2台服务器之间使用负载均衡器。

在所有请求中,我在标题上发送 X-CSRF-TOKEN ,在表单数据中发送 _token

有时请求有效但有时却没有。

由于

1 个答案:

答案 0 :(得分:0)

通过启用@ Michael-sqlbot上面写的粘性来解决。