简体   繁体   English

Ajax请求已发送到服务器,但返回状态码0

[英]Ajax request sent to server but returns status code 0

My application uses phonegap 1.7.0 and jquery 1.7.1 bundled in an android app. 我的应用程序使用Android应用程序中捆绑的phonegap 1.7.0和jquery 1.7.1。 My html contains multiple getJson() calls which run successfully except one when i submit a form. 我的html包含多个getJson()调用,这些调用可以成功运行,但在我提交表单时除​​外。

$('#proposalForm1').submit(function(event){
    var formInput = $(this).serialize();
    $('#loader').show();
    $.getJSON("http://xxx.xxx.xxx.xxx:8282/Service004/user/jsProposalPage1.action",  formInput,function(data){
    $('#loader').hide();
    if(data.serviceErrorMsg == ""){
      window.location.replace("proposalDisplay.html");
    }
    else{
      alert(data.serviceErrorMsg);
    }
}).error(function(xhr){
        $('#loader').hide();
        alert(xhr.status);
        navigator.notification.alert(
            'Please try again later!',  // message
            doNothing,         // callback
            'Server Unavailable',            // title
            'Exit'                  // buttonName
            );
    });
    return false;
});

Sometimes it works, but mostly it returns error code 0.The app server to which the request is made receives the request successfully and calls a webs service. 有时它可以工作,但大多数情况下会返回错误代码0。向其发出请求的应用服务器成功接收到该请求并调用Web服务。 The response from the web service is received by the app server successfully, but the phonegap app reports a staus code 0. Can anyone please help me? 应用服务器已成功收到来自Web服务的响应,但是phonegap应用报告的状态码为0。有人可以帮助我吗? The same problem exists when the app is bundled for blackberry using Web works and not phone gap. 当使用Web Works将应用程序捆绑到Blackberry而不是手机间隙时,存在相同的问题。 Tested on Android 2.3.3 and Blackberry 9300 curve. 在Android 2.3.3和Blackberry 9300曲线上进行了测试。

Thanks in advance, 提前致谢,

I would recommend switching your $.getJSON call to a full $.ajax() call and setting the timeout to something a little longer. 我建议将$ .getJSON调用切换为完整的$ .ajax()调用,并将超时时间设置得更长一些。 It's probably due to the fact the your webservice takes too long to reply. 这可能是由于您的Web服务需要很长时间才能回复。

If this doesn't work, you may need to configure your app server to wait to reply until it has the response. 如果这不起作用,则可能需要将您的应用服务器配置为等待答复,直到获得响应为止。 Status code 0 means that "the response was empty, (as not even headers were returned). This means the connection was accepted and then closed gracefully (TCP FIN)." 状态代码0表示“响应为空,(甚至没有返回标头)。这表示已接受连接,然后正常关闭(TCP FIN)。”

There are a number of things which could cause this, most likely a timeout in your case, but a firewall could also be the culprit, (less likely, as the app server was working for other requests). 有很多原因可能导致这种情况,在您的情况下最有可能是超时,但是防火墙也可能是罪魁祸首(可能性很小,因为应用服务器正在处理其他请求)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM