I’m trying to make JQUERY and PHP communicate with some strange results
Here’s the JQuery
$.ajax({
type : "GET",
url : "background.php",
dataType: 'json',
success : function(response){
alert("OK: " + immagini);
},
error: function(xhr, ajaxOptions, thrownError){
eval('var immagini = xhr.responseText');
alert("CODE: " + xhr.status);
alert("ERROR: " + immagini + "\n\n\nTIPO: " + typeof immagini);
}
});
And here’s the PHP
<?php
include "amministrazione/config.php";
include "amministrazione/database.php";
header("Content-type: application/json");
$db = new DB($db_server,$db_name,$db_user,$db_pass);
echo $db->loadBackgroundImages();
?>
And finally there is the answer I build from PHP function
{'immagini':[{'image': 'gallery/alto.jpg'},{'image': 'gallery/esterno.jpg'},{'image': 'gallery/gelateria.jpg'},{'image': 'gallery/vitelli.jpg'}]};
Strange thing is that the Jquery ends up in the error handler even if code is 200… how can I fix this?
This shouldn’t be a Cross-Domain problem, since they are on the same directory on EasyPHP, or am I wrong?
Many thanks,
Tiwiz
change single quote to double quote in your json