简体   繁体   English

第一个ajax调用状态为0“错误”,但第二个ajax调用状态为4“ 200”

[英]First ajax call status 0 “error” but second ajax call status 4 “200”

I ran into a serious problem. 我遇到了一个严重的问题。 Firstly: 首先:

Ajax call is sent by cordova app on an Android device to a Windows Server (IIS, PHP) protected by base authentication and ssl. Ajax呼叫由Android设备上的cordova应用发送到受基本身份验证和SSL保护的Windows Server(IIS,PHP)。

Since we updated the GlobalSign nv-sa certificate last time (some days ago) the ajax call gets status 0 at the first try after 30 seconds, but status 4 and "200" on the second try (Tapping first time after 30 seconds status 0 -> tapping second time status 4 immediately). 由于我们上次(几天前)更新了GlobalSign nv-sa证书,因此ajax调用在30秒后的第一次尝试中获得状态0,但是在第二次尝试中获得状态4和“ 200”(在30秒后首次点击状态0 ->立即点击第二时间状态4)。 The only difference to the old certificate is: the new one is not anymore sha1 but sha256 fingerprint... 与旧证书的唯一区别是:新证书不再是sha1,而是sha256指纹...

From the second tap on, every tap results in 4 "200" without any problems but first one always gets 0 "error". 从第二次点击开始,每一次点击都会得到4“ 200”,而没有任何问题,但是第一个总是得到0“ error”。

Code: 码:

$.ajax({
          type: "POST",
          url: url,
          async: asyncVar, // for Android: false - for iOS: true

          username: db.getItem("user"),
          password: db.getItem("pass"),
          xhrFields: { withCredentials: true },

          data: { forename: db.getItem("forename"), surname: db.getItem("surname"), uuid: db.getItem("uuid"), mail: db.getItem("mail"), phone: db.getItem("phone") },
          dataType: "json",
          success: function(data, status, object){
            var body = object.responseText;
            var obj = jQuery.parseJSON(body);

            alert('test1: '+status + ' | ' + object.status + ' | ' + object.readyState + ' | ' + object.statusText + ' | ' + data);

            //alert("test: "+obj.auth);

            if(obj.auth == '1')
            {
                db.setItem("auth","1");
            }
            else
            {
                db.setItem("auth","0");
            }
        },
        error: function(object, status, errorThrown){
            db.setItem("auth","0");
            alert('test2: '+status + ' | ' + object.status + ' | ' + object.readyState + ' | ' + object.statusText + ' | ' + errorThrown);
        }
}).always(function(object, status, errorThrown){
        if(db.getItem("auth") == "1")
        {
            $.mobile.pageContainer.pagecontainer("change","#pageLocations");
        }
        else
        {
            db.setItem("auth","0");
        }
        alert('test3: '+status + ' | ' + object.status + ' | ' + object.readyState + ' | ' + object.statusText + ' | ' + errorThrown);
});

Exact result of code: 代码的确切结果:

First tap: 第一次点击:

test2: error | 0 | 0 | error |
test3: error | 0 | 0 | error |

Second, third, etc... tap: 第二,第三等...点击:

test1: success | 200 | 4 | OK | [object Object]
test3: success | undefined | undefined | undefined | [object Object]

Do you have any idea what could be the reason for this or am I doing anything wrong? 您是否知道这可能是什么原因,或者我做错了什么?

Thnx. 谢谢 in advance for your help. 提前为您提供帮助。

OK, I got it to work now. 好的,我现在开始工作了。 The solution was simple: 解决方案很简单:

The intermediate certificate of GlobalSign was missing, so we installed it on the server, restarted it and it worked... 缺少GlobalSign的中间证书,因此我们将其安装在服务器上,然后重新启动即可使用...

There was no problem with the source code! 源代码没有问题! Just the certificate and the intermediate certificate had to be installed. 只需要安装证书和中间证书。

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

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