jQuery的:错误早报脱机后(的iOS&安培;镀铬)安培、镀铬、早报、错误

2023-09-10 17:21:30 作者:亡命爱人

我已经建立了一个HTML5的web应用程序离线功能(使用AppCache)。该程序流程是:

I've built an HTML5 web application with offline capabilities (using AppCache). The program flow is:

在线:而网络的上,应用程序pre-加载一些基本信息(工作) 离线:用户需要的平板电脑上使用的应用程序的离线的,则执行其上的应用程序的工作流(如检查和分级) 在线:当平板电脑的重新连接到,它同步网络的(或上传)将用户输入到中央系统/数据库 Online: While on the network, the app pre-loads some base information ("working"). Offline: The user takes the tablet with the app offline, then performs their workflow on the app (e.g. inspections and grading). Online: Once the tablet reconnects to the network, it syncs (or uploads) the user's input into the central system/database.

我们已经取得了使用Chrome的所有脱机业务决策。在Windows设备(使用Chrome),同步/上载作品,没有任何问题。如果用户是使用一台iPad(iOS的7,Chrome浏览器),他们首次尝试同步,则会引发错误 - 但最开头的记录实际上是同步的。由该XHResponse对象抛出的误差仅仅是错误。

We have made a business decision to use Chrome for ALL offline/HTML5 applications (because of HTML5 support). On a Windows device (using Chrome), the sync/upload works with no problems. If the user is using an iPad (iOS 7, Chrome), the first time they try to sync, an error is thrown - however the very first record IS actually synced. The error that is thrown by the XHResponse object is just "error".

我们都在服务器端使用的WebAPI 2.2和jQuery 2.1.1 AJAX客户端上。

We are using WebAPI 2.2 on the server side, and jQuery 2.1.1 AJAX on the client side.

客户端的JavaScript 执行的POST如下:

The client-side JavaScript that performs the POST is as follows:

try {
    var inspections = GetCompleteInspections();
    if (inspections) {
        for (var i = 0; i < inspections.length; i++) {
            var response = null;
            var data = JSON.stringify(inspections[i]);
            $.ajax({
                async: false,
                type: "POST",
                url: "api/",
                data: data,
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (dta, textStatus, xhr) {
                    window.console.log("data:" + dta + "--");
                    if (d && d < 0) {
                        alert("dta is invalid:" + dta + "--");
                        response = "Error Uploading, please try again";
                    } else {
                        $("#inspection_" + i).hide();
                    }
                },
                error: function (xhr, textStatus, errorThrown) {
                    if (textStatus == "timeout") {
                        alert("timeout!");
                        response = "timeout";
                    } else {
                        window.console.log(xhr.responseText);
                        var errorMessage = errorThrown || xhr.statusText;
                        response = errorMessage;
                    }
                }
            });
            if (response) {
                throw response;
            }
        }
    }
    $('#new_records').append("<tr><td>Sync Complete</td></tr>");
    $('#syncButton').hide();
    ClearInspections();
    $("#dialog-sync").dialog("close");
} catch (err) {
    $("#dialog-sync").dialog("close");
    window.alert("An error occurred during upload\n" + err);
}

这似乎只发生在运行的Chrome iOS设备。 Windows设备没有这个问题。有没有办法追查或诊断是怎么回事?甚至如何prevent错误的发生?

This only appears to happen on iOS devices running Chrome. Windows devices do not have this issue. Is there any way to trace or diagnose what is going on? Or even how to prevent the error from happening?

推荐答案

我有一次我在一个真正的总的方法砍死围绕一个非常类似的问题:

I had a very similar problem once which I hacked around in a truly gross way:

在执行同步,予装一个可见的1x1透明PNG从网络(设置与随机查询字符串的源,以避免缓存)。然后,当图像装载(onload事件),我开始了JavaScript调用。

Before doing the sync, I loaded a visible 1x1 transparent png from the network (set the source with a random query string to avoid caching). Then when that image loaded (onload event) I started the JavaScript calls.

为了这一天,我不知道是否有某种潜在的网络问题,或者如果这只是解决了通过引入在启动时的时间延迟,但问题永不复发,并没有拿出在野外。试想想,它也许是时候重构了code ...

To this day I don't know if there's some underlying network issue or if this only solved it by introducing a time delay on startup, but the problem never recurred and hasn't come up in the wild. Come to think of it, it's probably time to refactor that code...