I have a problem with an ajax request, when I do the request with the property dataType: 'json', my response come with an error, parsererror, my function in PHP returns the data like json_encode(), pls, can you help me? when I do the request without property dataType: 'json' my data is ALL THE DOCUMENT HTML.
My request:
var dataAr = {Latitude: Latitude, Longitude: Longitude};/
console.log(dataAr);
$.ajax({
data: dataAr,
dataType: 'json',
type: 'POST',
url: 'http://localhost/GPS/Server.php/GPS/Coords',
success: function (data, response) {
console.log('Data: '+data);
console.log('Response: '+response);
},
error: function (textStatus, errorThrown) {
console.log('Status: '+textStatus);
console.log('Error: '+errorThrown);
}
});
My function in PHP:
class GPS
{
function Coords()
{
$Res=$_POST['data'];
$Latitude=$_POST['Latitude'];
$Longitude=$_POST['Longitude'];
return json_encode($Res);
}
}