Internet 连接错误消息 - 带有 Javascript 的 Windows 8 应用程序 [英] Internet connection error message - Windows 8 Application with Javascript

查看:25
本文介绍了Internet 连接错误消息 - 带有 Javascript 的 Windows 8 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为我的应用程序添加一个基本检测脚本,以允许它在调用 WinJS.xhr 失败时显示错误消息.

I am trying to add a basic detection script for my application to allow it to display an error message when a call to WinJS.xhr fails.

我让每个 WinHS.xhr 在出错时调用以下函数(使用 .done() 的第二个参数),这部分运行良好.

I have every WinHS.xhr call the following function onerror (using the 2nd param of .done()) and that part is working great.

function connectionError() {
    var msg = new Windows.UI.Popups.MessageDialog("There was a connection error while trying to access online content. Please check your internet connection.");

    // Add commands and set their CommandIds
    msg.commands.append(new Windows.UI.Popups.UICommand("Retry", null, 1));

    // Set the command that will be invoked by default
    msg.defaultCommandIndex = 1;

    // Show the message dialog
    msg.showAsync();
}

当我显示对话框时出现问题.出于某种奇怪的原因,我在尝试显示对话框时收到拒绝访问"错误消息.我检查了该消息的含义,如果我理解正确的话,它似乎是某处未完成的承诺,尽管我看不出有任何方法可以将其应用于我的情况.

The problem arises when i display the dialog. For some weird reason i get an "Access Denied" error message when trying to show the dialog. I checked the meaning of that message and it seems to be some unaccomplished promise somewhere if i understood correctly, although i don't see any way to apply this to my situation.

感谢有关此错误的任何帮助!

Any help regarding this error is appreciated!

推荐答案

您在这里面临的问题是您无法将多个消息对话框堆叠在一起——例如,您一次只能显示一个.我使用以下代码在我的应用程序中解决了这个问题:

The problem you are facing here is that you cannot stack multiple message dialogs on top of each other -- e.g you can only display one at a time. I solved this in my application using the following code:

    (function () {
        var alertsToShow = [];
        var dialogVisible = false;

        function showPendingAlerts() {
            if (dialogVisible || !alertsToShow.length) {
                return;
            }

            dialogVisible = true;
            (new Windows.UI.Popups.MessageDialog(alertsToShow.shift())).showAsync().done(function () {
                dialogVisible = false;
                showPendingAlerts();
            })
        }
        window.alert = function (message) {
            if (window.console && window.console.log) {
                window.console.log(message);
            }

            alertsToShow.push(message);
            showPendingAlerts();
        }
    })();

这会将它们排队并依次显示它们.显然这不适用于您的情况,但这应该是一个很好的起点.:)

This will queue them up and display them one-after the other in succession. Clearly this won't work for your case, but this should be a good starting point. :)

这篇关于Internet 连接错误消息 - 带有 Javascript 的 Windows 8 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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