use
{{ action('Controller@function') }}
Summer Sale! All accounts are 50% off this week.
Dear all,
I have a few issues using AJAX requests to process form data. I would like to use the googlemaps API V3 in Javascript for geocoding purpose.
The workflow should be as follows:
My problem is now this: The Lat/Lng Informatin by Google Maps API is client-side information whereas the rest of the stuff is processed server side. So I want to inform my server about this additional information as well.
Therefore I thought about using an AJAX request to pass this client-side information to the server. But I get stuck here. I do want to make sure, that before the server-side function in the controller is storing all information, the additional Lat/Lng info is added to the data before and then stored to the database.
Here
This is the JS method:
function reverseGeocodeAddress() {
$.ajax({
type: "POST",
url: 'IncidentController@receiveReverseGeocodeInformation',
data: "",
success: function() {
console.log("Geodata sent");
}
})
};
I want to use an AJAX request to send the information to the server. But how do I tell the method to which method in the controller I want to sent to? the method you see there should be the one that processes the info server-side.
Here is the the code I wrote so far:
Controller:
public function createIncident(PrepareIncidentRequest $request)
{
$data = $request->all();
$data = $data + [
'incidentReference' => TicketSystem::generateIncidentReference(),
'incidentID' => TicketSystem::generateIncidentID(),
'date' => Carbon::now()->format('Ymd')
];
$incident = Incident::create($data);
Auth::user()->incidents()->save($incident);
}
public function receiveReverseGeocodeInformation(Request $request) {
if(Response::ajax()) return "OK";
}
JavaScript Function with AJAX request
function reverseGeocodeAddress() {
$.ajax({
type: "POST",
url: 'IncidentController@receiveReverseGeocodeInformation',
data: "",
success: function() {
console.log("Geodata sent");
}
})
};
I want to use a certain function in the controller to receive the information from the AJAX request. As you can see in the receiveReverseGeoCodeInformation method in the controller, I added some test response. But I don't get it to work. Do I miss something here?
app/Http/routes.php file, create a route for this controller method: Router::post('geo-info-response', 'IncidentController@receiveReverseGeocodeInformation');
function reverseGeocodeAddress() {
$.ajax({
type: "POST",
url: './geo-info-response',
data: "",
success: function() {
console.log("Geodata sent");
}
})
};
Please or to participate in this conversation.