im trying to get JSON data from the server through an AJAX call. The call works fine, but the success handler does not receive the correct JSON data generated by the server, instead it receives all the HTML content on the current page.
My PHP code ( $_POST['idFoto']exists):
header('Content-type: application/json');
$fotos = FotoQuery::Create()->findByIdfoto($_POST['idFoto']);
if($fotos->count() != 1){
die("{success: false, msg: 'Error interno, foto no encontrada unívocamente.'}");
}
$foto = $fotos->getFirst();
$response = Array('success'=>true,'title'=>$foto->getTitulo(),'nombre'=>$foto->getNombre(),
'desc'=>$foto->getDescripcion(),'date'=>$foto->getFecha());
echo json_encode($response);
My Ajax call:
$.ajax({
url: document.domain +"/private/ajaxRequests/fotoRequestHandler.php",
method: "POST",
data: {idFoto: picId},
success: function(data,status,request) {
console.log(data);
console.log(status);
console.log(request);
}
});
Call the status "200 OK". Any ideas why this is not working properly?
UPDATE: . When running a script through a URL (with manually assigned idFoto) it json_encodeworks fine:
{"Success": true, "Name": "Demo 1", "nombre": "01.jpg", "desc": "Descripci \ u00f3n foto demo 1" "date": "07/24/13"}
, die(json_encode($response)) script, Ajax Call HTML.
. Smarty URLS, ?