getJSON を php 配列でテストしていますが、機能していません。誰かチェックしてもらえますか? getJSON url https://graph.facebook.com/zombiesを使用して html コードをテストすると、動作しているため、問題は php コードにあると感じています。
私のarray.phpで
<?php
header("Content-type: text/javascript");
$arr = array(
"name" => "Tim",
"age" => "28" );
echo json_encode($arr);
?>
私の test.html で:
<html>
<head>
<script type='text/javascript' src='jquery.js'></script>
</head>
<body>
<script type='text/javascript'>
$(document).ready(function() {
$.getJSON('array.php', function(data) {
if(data) {
document.write(data.age);
}
else {
alert('error');
}
});
});
</script>
</body>
</html>