gpt4 book ai didi

javascript - 尽管我的路径是正确的,但在 map 上显示某些内容时,我在 laravel 中收到错误 419

转载 作者:行者123 更新时间:2023-11-30 20:09:55 31 4
gpt4 key购买 nike

我正在使用 google maps api 创建一个应用程序,允许用户在特定位置添加标记但是当我点击 map 添加位置时,我返回的所有数据都是正确的,但我得到错误 19 的响应代码......这是我保存数据的代码

function saveData(lat,lng) 
{

console.log("LAT:"+lat+" LNG:"+lng);

var description = document.getElementById('manual_description').value;
var formData = new FormData();
console.log("DESC:"+description);
formData.append("latitude", lat); //outputs correctly
formData.append("longitude", lng);//outputs correctly
formData.append("description", description); //outputs correctly
console.log(formData.get("latitude")+" "+formData.get("longitude")+" "+formData.get("description"));

downloadUrl(formData, function(data, responseCode) {
console.log("RESP:"+responseCode);
console.log(data.length);
if (responseCode === 200 && data.length > 1) {
var markerId = getMarkerUniqueId(lat,lng); // get marker id by using clicked point's coordinate
var manual_marker = markers[markerId]; // find marker
manual_marker.setIcon(purple_icon);
infowindow.close();
infowindow.setContent("<div style=' color: purple; font-size: 25px;'> Waiting for admin confirm!!</div>");
infowindow.open(map, manual_marker);

}else{
console.log("RESPONSECODE: "+ responseCode); //419
console.log("DATA: "+data); //html data with title of Page Expired
infowindow.setContent("<div style='color: red; font-size: 25px;'>Inserting Errors</div>");
}
});

function downloadUrl(formData, callback)
{

var xhttp = new XMLHttpRequest;
xhttp.onreadystatechange = function() {
console.log(xhttp.readyState);
if (xhttp.readyState == 4) {
callback(xhttp.responseText, xhttp.status);
}
};

xhttp.open("POST", "http://localhost/cacheFinder/public/save");
xhttp.setRequestHeader('X-CSRF-TOKEN', '{{ csrf_token() }}');
xhttp.send(formData);
}

这是我的路线 Route::post('save', 'MarkersController@save');

这是保存函数:

 public function save(Request $request){

$lat = $request->input("latitude");
$lng = $request->input("longitude");
$description = $request->input("description");

Marker::create([

'latitude'=>$lat,
'longitude'=>$lng,
'description'=>$description
]);


return redirect('usermap');
}

任何帮助将不胜感激

最佳答案

将此添加到您的VerifyCsrfToken 中间件

protected $except = [
'/cacheFinder/public/*'
];

xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

xmlhttp.setRequestHeader('X-CSRF-TOKEN',window.Cookies.get('_csrf'));

关于javascript - 尽管我的路径是正确的,但在 map 上显示某些内容时,我在 laravel 中收到错误 419,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52515638/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com