duanchouyi6730 2015-06-04 12:16
浏览 25
已采纳

尽管网络请求正在成功发送,但jQuery发布并且没有返回任何内容

I have the following javascript function:

function test() {
 jQuery.post("http://www.example.com/test.php", {})
 .done(function(data) { 
            alert(data); 
 })
 .fail( function(xhr, textStatus, errorThrown) {
            console.log(xhr);
            console.log(textStatus);
            console.log(errorThrown);
 });

}

And the test.php file reads like this:

 <? echo "TEST"; ?>

When I call this function either by clicking on something on my page, either by typing it to the console, the alert is not firing, instead the fail part of the jQuery.post is being fired, where I get the following values:

xhr -> object

textStatus -> "error"

errorThrown -> ""

I've checked firefox debugers network, where I see that the request is being sent to the desired url, and the little circle at the left side gets green, which means that I get some kind of response from the server, but the transfered column is a single "-" line, and the received column is 0 bytes. If I call the page "http://www.example.com/test.php" from a browser, it works correctly.

What could be the problem, or how could I proceed on debuging this error?

Figured out the problem, see my own answer below, if anyone experiences the same error:|

  • 写回答

1条回答 默认 最新

  • dongying195959 2015-06-04 12:22
    关注

    Figured out the problem. I was accessing my site as example.com from the browser, and not as www.example.com where I send my ajax request. Ajax handled the request as cross-domain and that's why I didn't get an answer... dumb me...

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入
  • ¥20 XP系统在重新启动后进不去桌面,一直黑屏。
  • ¥15 opencv图像处理,需要四个处理结果图
  • ¥15 无线移动边缘计算系统中的系统模型