I'm struggling with sending the marker coordinates to a controller using ajax. I have named my routes 'update-marker-position' and included csrf_token(), but I am still seeing an error message in the logs.
In my web.php file:
Route::post('/update-marker-position', [MarkerController::class, 'updatePosition'])->name('update-marker-position');
Below is my code snippet:
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);
});
Error message in logs:
500 (Internal Server Error)