jqueryを使用してクロスドメインリクエストを作成しようとしました。これは、クライアント側がどのように見えるかです。
<script src="js/jquery-1.6.2.min.js"></script>
<script type="text/javascript">
$(document).ready( function(){
$.ajax({
type: 'GET',
url: "http://www.xserver.com/xdomainhandler.php",
processData: true,
data: {
type:"gotohell"
},
dataType: "json",
success: function (data) {
myglob=data;
var repo=JSON.parse(myglob);
alert(repo.type);
},
error : function(XMLHttpRequest, textStatus, errorThrown){
alert('ends up in error state');
}
});
});
</script>
このリクエストを受け取るサーバー ページのコードは次のようになります。
<?php
header('Access-Control-Allow-Origin: *');
header('Expires: ' . gmdate('r', 0));
header('Content-type: application/json');
session_cache_limiter('nocache');
$arr = array ('response'=>'success','comment'=>'test comment here','type'=>$_GET['type']);
echo json_encode($arr);
?>
しかし、リクエスト/レスポンス プロセスを完了したとき、「repo」変数には何も入っていませんでした。firebug を使用して応答を確認したところ、次のような応答が表示されます。
{"response":"success","comment":"test comment here","type":"gotohell"}
また、表示される firebugの DOM パネルで myglob変数を確認しました。
Object { response="success", comment="test comment here", type="gotohell"}
しかし、myglob をレポに解析すると、何も表示されません。どこが間違っているのか。誰か助けてくれませんか。ありがとう!