我对 jQuery 1.9.1 和 json 响应有疑问。我的 html-File 测试非常简单(使用 jQuery 1.8.3):
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$.ajax({
url: "php/news_test.php",
dataType: "json",
success: function(json){
$("#news-box").html(json.news.name);
}
});
</script>
</head>
<body>
<div id="news-box"></div>
</body>
</html>
这适用于以下 php 文件:
header('Content-type: application/json');
include('core/database.php');
/*
$db = new Database();
...
...
...
*/
echo json_encode(array("news" => array("name" => "Test")));
但是当我更改为 jQuery 1.9.1 时,我没有得到回应。我必须评论第二行include('core/database.php');
之后我得到了 jQuery 1.9.1 的回复。database.php 只有一行用于测试$db_host = 'localhost';
我不能在 jQuery 1.9.1 中使用包含吗?我的代码有错误吗?或者它是一个错误?