我用这jQuery.ajax响应:jQuery的阿贾克斯 - 不能得到
var url = "http://client.my_url.com/test_get_account_data.php";
jQuery.ajax({
type: "GET",
url: url,
cache: false,
success: function(resultsData){
alert("We're finally making the call.");
},
error:function (jqXHR, textStatus, errorThrown){
alert("Error:" + textStatus+ "," + errorThrown);
}
});
为了打这个PHP脚本:
<?php
header("Content-Type: text/plain");
$myFile = "LogFile.log";
$fh = fopen($myFile, 'w');
$accountJSON = array("id"=>"Level 3.accountName","type"=>"Level 3","name"=>"accountName","total"=>"1059.25","in"=>"8603.56","out"=>"7544.31");
$encodedResponse = json_encode($accountJSON);
fwrite($fh, "We're at the end of get_account_data with encodedResponse:\n");
fwrite($fh, $encodedResponse."\n");
echo $encodedResponse;
?>
但由于某些原因,我从来没有得到一个成功。我尽可能简化了这一点,但仍然失败。在日志中,我有输出:
We're at the end of get_account_data with encodedResponse:<br/>
{"id":"Level 3.accountName", "type":"Level 3", "name":"accountName", "total":"1059.25", "in":"8603.56", "out":"7544.31"}
有没有人有什么建议?我会认为这很容易......也许是这样,我只是在做一些愚蠢的事情。
感谢
你的浏览器的Javascript错误控制台说什么? – 2012-03-10 23:07:13
您的网页是否与PHP服务器在同一个域上?浏览器的错误控制台或调试控制台是否会报告任何javascript错误或安全错误? – jfriend00 2012-03-10 23:07:32
试过'header(“Content-Type:application/json”);'?你实际上并没有发回纯文本,是吗? – Matijs 2012-03-10 23:11:34