jQuery1.9.1とjsonの応答に問題があります。私のhtmlファイルはテストが非常に簡単です(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-Fileで正常に機能します。
header('Content-type: application/json');
include('core/database.php');
/*
$db = new Database();
...
...
...
*/
echo json_encode(array("news" => array("name" => "Test")));
しかし、jQuery 1.9.1に変更すると、応答がありません。2行目にコメントする必要がありますinclude('core/database.php');
。その後、jQuery1.9.1で応答が返されます。database.phpには、テスト用の1行しかありません$db_host = 'localhost';
jQuery 1.9.1でインクルードを使用できませんか?コードにエラーがありますか?それともバグですか?