AJAX响应搞砸科尔多瓦应用程序在Windows Phone 8.1 [英] AJAX responses messed up in Cordova application on Windows Phone 8.1

查看:132
本文介绍了AJAX响应搞砸科尔多瓦应用程序在Windows Phone 8.1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们使用的是科尔多瓦3.4.0开发的应用程序。一切正常的Andr​​oid和iOS并且,如果我们推出的桌面浏览器我们的应用程序。但是,我们在Windows Phone 8.1坚持了很奇怪的问题。

We are using Cordova 3.4.0 to develop an app. Everything works fine on Android and iOS and also if we launch our app in a desktop browser. But we are stuck with really strange issue on Windows Phone 8.1.

下面是一个简单的code为例进行测试。

Here is a simplified code example to test.

index.html的应用程序根:

index.html in the application root:

<!DOCTYPE html>
<html>
    <head>
        <title>Mobile sandbox</title>
        <meta charset="UTF-8">
        <script type="text/javascript" src="libs/jquery/jquery.min.js"></script>
    </head>
    <body>

        <div id="redbox" style="width:100px;height:100px;background-color:red;">
        </div>

        <div id="greenbox" style="width:100px;height:100px;background-color:green;">
        </div>

        <script>
            $(function () {

                alert("Requesting data for redbox...");

                $.ajax("test/redText.html")
                  .done(function (text) {
                      alert("Filling redbox with contents " + text);
                      $("#redbox").html(text);
                  })
                  .fail(function () {
                      alert("Error in redbox");
                  })
                  .always(function () {
                      alert("Complete redbox");
                  });

                alert("Requesting data for greenbox...");

                $.ajax("test/greenText.html")
                  .done(function (text) {
                      alert("Filling greenbox with contents " + text);
                      $("#greenbox").html(text);
                  })
                  .fail(function () {
                      alert("Error in greenbox");
                  })
                  .always(function () {
                      alert("Complete greenbox");
                  });

            });
        </script>
    </body>
</html>

测试/ greenText.html:

test/greenText.html:

<span>GREEN</span>

测试/ redText.html:

test/redText.html:

<span>RED</span>

唯一的依赖来运行这个测试,我们已经把库/ jQuery的/文件夹jQuery的。

The only dependency to run this test is jQuery which we have put in libs/jquery/ folder.

现在,如果我们在每一个桌面浏览器在iOS和Android上运行此code,无论从本地文件夹(与本地AJAX浏览器的标志),或从服务器中,我们得到警报和AJAX正确的顺序加载正确的数据在相应的框中:

Now, if we run this code in every desktop browser and in iOS and Android, no matter if from local folder (with browser flags for local AJAX) or from server, we get the right sequence of alerts and AJAX loads correct data in appropriate boxes:

Requesting data for redbox...
Requesting data for greenbox...
Filling redbox with contents <span>RED</span>
Complete redbox
Filling greenbox with contents <span>GREEN</span>
Complete greenbox

我们得到相同的结果,如果我们通过它的Internet Explorer中运行在Windows Phone中的index.html。

We get the same result if we run the index.html on Windows Phone through its Internet Explorer.

但是,当我们部署相同的code到Windows Phone作为科尔多瓦应用程序,奇怪的事情发生了。该红盒子的要求从来没有接收到任何数据,也没有任何错误。该绿盒子要求接收红盒子的数据,因此,我们必须在空红色框和绿框的文本红它。 这是警报的顺序:

But when we deploy the same code to Windows Phone as Cordova app, strange thing happens. The redbox request never receives any data, nor any errors. The greenbox request receives data of redbox, and thus we have empty red box and green box with text "RED" in it. Here is the sequence of alerts:

Requesting data for redbox...
Requesting data for greenbox...
Filling greenbox with contents <span>RED</span>
Complete greenbox

这是怎么回事那里,为什么一个人的AJAX请求不返回,另一组接受错误的反应?我们如何解决这个问题?

编辑1:

我们的巢步骤是找出是否是科尔多瓦具体问题(我认为只有在Corodva WP8模板一些XHRHelper对象),或者是微软的电话:web浏览器故障

Our nest step will be to find out if it's Cordova specific issue (I see there is some XHRHelper object in the Corodva WP8 template) or it's Microsoft's phone:WebBrowser fault.

编辑2:

看来,web浏览器本身不支持AJAX请求对本地文件(我得到了拒绝访问),这就是为什么科尔多瓦发明XHRHelper类。但我发现,他们关闭,无法重现相关的错误报告: https://issues.apache.org/jira/browse/CB-4873

It seems, WebBrowser itself does not support AJAX requests to local files (I got "Access denied") and that's why Cordova invented XHRHelper class. But I found a related bugreport which they closed as "Cannot reproduce": https://issues.apache.org/jira/browse/CB-4873

有没有科尔多瓦开发商在这里谁可以建议对XHRHelper修复,所以它支持多个连续的AJAX请求?

Is there any Cordova developer here who could suggest a fix for XHRHelper, so it supports multiple sequential AJAX requests?

推荐答案

此外,我不能重现你的结果。我赶紧把一个版本,我会张贴到JIRA问题: https://开头的问题。 apache.org/jira/browse/CB-4873

Again, I cannot reproduce your results. I quickly put together a version which I will post to the JIRA issue: https://issues.apache.org/jira/browse/CB-4873

Requesting data for redbox...
Requesting data for greenbox...
Filling redbox with contents 
<span>REd</span>
Complete redbox
Filling greenbox with contents 
<span>GREEN</span>
Complete greenbox

我修改源一点点公正,以确保有与警报无干扰的问题...

I modified your source a little just to make sure there were no issues with alert interfering ...

var eventLog = [];
var oneDone = false;

$(function () {
    eventLog.push("Requesting data for redbox...");
    $.ajax("redText.html")
        .done(function (text) {
            eventLog.push("Filling redbox with contents " + text);
            $("#redbox").html(text);
        })
        .fail(function (e) {
            eventLog.push("Error in redbox" + JSON.stringify(e));
        })
        .always(function () {
            eventLog.push("Complete redbox");
            if (oneDone) {
                console.log(eventLog.join("\n"));
                alert(eventLog.join("\n"));
            }
            else {
                oneDone = true;
            }
        });

    eventLog.push("Requesting data for greenbox...");
    $.ajax("greenText.html")
        .done(function (text) {
            eventLog.push("Filling greenbox with contents " + text);
            $("#greenbox").html(text);
        })
        .fail(function () {
            eventLog.push("Error in greenbox");
        })
        .always(function () {
            eventLog.push("Complete greenbox");
            if (oneDone) {
                console.log(eventLog.join("\n"));
                alert(eventLog.join("\n"));
            }
            else {
                oneDone = true;
            }
        });
});

这篇关于AJAX响应搞砸科尔多瓦应用程序在Windows Phone 8.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆