jQuery Ajax-无法获得响应 [英] jQuery Ajax - can't get a response

查看:114
本文介绍了jQuery Ajax-无法获得响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此jQuery.ajax:

I am using this jQuery.ajax:

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;
?>

但是由于某种原因,我从未获得成功.我已尽我所能简化了此过程,但仍然失败.在日志中,输出为:

But for some reason, I never get a success. I've simplified this as much as I can imagine, but it still fails. In the log, I have the output:

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"}

有人有什么建议吗?我认为这很容易...也许是这样,而我只是在做一些愚蠢的事情.

Does anyone have any suggestions? I would think this would be very easy... and maybe it is and I'm just doing something stupid.

谢谢

推荐答案

似乎您正在尝试使用http://localhost:8080

根据浏览器的相同来源策略,您无法将AJAX GET/POST请求发送到另一个域.您需要将 JSONP 用于跨域AJAX.

According to same origin policy of browsers you cannot send AJAX GET/POST requests to another domain. You need to use JSONP for cross domain AJAX.

这篇关于jQuery Ajax-无法获得响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆