我在如何使用 ajax 将标记坐标发送到控制器方面遇到了麻烦。
我的路线名为“update-marker-position”,我也放置了 csrf_token(),但它仍然在日志中显示错误消息。
web.php
Route::post('/update-marker-position', [MarkerController::class, 'updatePosition'])->name('update-marker-position');
这是我的代码
google.maps.event.addListener(marker, 'dragend', function (event) {
const newLat = event.latLng.lat();
const newLng = event.latLng.lng();
const markerTitle = marker.getTitle();
$.ajax({
method: "POST",
url: '{{ route('update-marker-position') }}',
data: {
_token: '{{ csrf_token() }}',
title: markerTitle,
lat: newLat,
lng: newLng
},
success: function (response) {
console.log('Successfully updated:', response);
},
error: function (error) {
console.error('Error:', error);
}
});
// console.log('Shop:', markerTitle,' Latitude: ', newLat,' Longitude: ', newLng);
});
日志中出现错误
500 (Internal Server Error)
在 DevTools 中检查服务器错误 -> 转到网络选项卡并选择从过滤器中获取/XHR 结果,然后选择状态为 500 的请求,然后转到预览以查看服务器错误详细信息