0

我试图让 JQUERY 和 PHP 以一些奇怪的结果进行通信

这是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);
 }
}); 

这是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();
?>

最后是我从 PHP 函数构建的答案

{'immagini':[{'image': 'gallery/alto.jpg'},{'image': 'gallery/esterno.jpg'},{'image': 'gallery/gelateria.jpg'},{'image': 'gallery/vitelli.jpg'}]};

奇怪的是,即使代码是 200,Jquery 也会出现在错误处理程序中......我该如何解决这个问题?

这不应该是跨域问题,因为它们在 EasyPHP 上的同一目录中,还是我错了?

非常感谢,

蒂维兹

4

1 回答 1

0

在您的json中将单引号更改为双引号

{"immagini":[{"image": "gallery/alto.jpg"},{"image": "gallery/esterno.jpg"},{"image": "gallery/gelateria.jpg"},{"image": "gallery/vitelli.jpg"}]}
于 2012-04-25T10:03:58.077 回答