【问题标题】:troubleshooting jquery/ajax json data retrieve对 jquery/ajax json 数据检索进行故障排除
【发布时间】:2016-12-25 12:32:59
【问题描述】:

我将以下代码上传到 tomcat 服务器中,该代码假设从其他服务器检索信息,由于某种原因,这没有发生,没有来自其他服务器的回复以下是代码我收到错误功能警报“握手”没有通过”

$(document).ready( function() {
    var home_add='http://mywebsite.net:3300/gateway';
    $('#handshake').click(function(){
         alert(" sending json data");
         $.ajax({                 /* start ajax function to send data */ 
             url:home_add,
             type:'POST',
             datatype:'json',
             contanttype:'text/json',
             async: false, 
             error:function(){ alert("handshake didn't go through")}, /* call disconnect function */
             data: {
                 "supportedConnectionTypes": "long-polling",
                 "channel": "/meta/handshake",
                 "version": "1:0"
             },
             success: function(data) {
                 $("p").append(data+"<br/>");
                 alert("sucessful handshake");
             }                    
         });
     });
});

我检查了 firebug net 面板,我收到了以下请求标头,但没有响应,也没有 xhr,请给我你的反馈

mywebsite.net:3300
User-AgentMozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.13) Gecko/20101209 CentOS/3.6-2.el5.centos Firefox/3.6.13
Accepttext/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Languageen-us,en;q=0.5
Accept-Encodinggzip,deflate
Accept-CharsetISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive115
Connectionkeep-alive
Originhttp://127.0.0.1:8080
Access-Control-Request-Me...POST 

【问题讨论】:

标签: jquery ajax web-services json firebug


【解决方案1】:

这听起来你可能有跨域脚本的问题。如果您要从中获取数据的域与您网站的域不同,则需要使用 JSONP 从中获取数据。

【讨论】:

    猜你喜欢
    • 2020-11-18
    • 2014-07-04
    • 1970-01-01
    • 2011-10-02
    • 2020-10-02
    • 2011-02-07
    • 2013-11-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多