【问题标题】:ajax call not respondingajax调用没有响应
【发布时间】:2012-06-01 22:03:19
【问题描述】:

ajax 调用创建问题。它在浏览器中运行良好,但不会通过 ajax 调用。网址在这里http://testbed2.baileyprofile.com/dd-api.php?test=1

当我在 Firefox 检查元素控制台中检查它时。它发送请求并在大约 900 毫秒或 mroe 后给出消息 200 Ok 并且 url 颜色变为红色。它根本不产生任何响应。

请任何提示它可能有什么问题。 我的代码如下

 jQuery.post(ajaxurl, {action: 'test' }, function(response) {
        if (response!= '') {
             jQuery('#test-result').html("Restule is generated successfully, copy of result has been sent to your inbox").fadeOut(10000);
             document.getElementById("txtFeedback").value= response;
            //console.log(response.data);
            //alert('POST title: ' + response.data.post_title);
        } else {
            // something didn't go well
            console.log(response.status);
        }
    });

【问题讨论】:

  • 实际上在检查模式下的 url 变成红色并且它没有给出任何响应。任何响应都是简单的文本。
  • 有人想通知您此请求正在其他服务器上进行。意味着我有 a.com 并向 b.com 发送请求。有什么问题吗?
  • See my updated answer,有什么问题就是问题!

标签: jquery ajax same-origin-policy


【解决方案1】:

更新:

我有 a.com 并向 b.com 发送请求。会不会有什么问题?

你违反了Same origin policy,你不能从域a.comb.com进行ajax

【讨论】:

  • 我已经使用了这段代码,它显示了消息 "error" 'code' var jqxhr = jQuery.ajax({type: "GET",url: "212.124.100.44/gmemo/dd-api.php",data:{'test':' 1'} }) .done(function() { alert("success"); }) .fail(function(jqXHR, textStatus) { alert("error"+ textStatus); })
  • 那么我该如何解决这个问题。我需要向其他服务器发送请求并需要来自它的数据。
  • @nbhatti2001。 <iframe>jsonp 呢?
  • 让我解释一下我的情况。我将在服务器 A 上进行测试并将该数据发送到服务器 B,服务器必须准备结果并将其发送给用户,然后发回我在当前屏幕上显示的快速结果。但我不想换屏。请帮助我如何实现这一目标?
  • 我调用 ajax 到本地页面,然后通过调用 get_file_contents() 函数从其他站点获取数据并通过邮寄方式发送数据。这解决了我的问题。
【解决方案2】:

数据参数应该在''之内。试试吧,它应该可以工作

jQuery.post(ajaxurl, {'action': 'test' }, function(response) {
        if (response!= '') {
             jQuery('#test-result').html("Restule is generated successfully, copy of result has been sent to your inbox").fadeOut(10000);
             document.getElementById("txtFeedback").value= response;
            //console.log(response.data);
            //alert('POST title: ' + response.data.post_title);
        } else {
            // something didn't go well
            console.log(response.status);
        }
    });

【讨论】:

    猜你喜欢
    • 2015-10-31
    • 1970-01-01
    • 2011-03-11
    • 2019-08-09
    • 1970-01-01
    • 2012-04-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多