如何在WinJS.xhr无法连接时打印有用的错误消息? [英] How to print useful error messages when WinJS.xhr could not connect?

查看:93
本文介绍了如何在WinJS.xhr无法连接时打印有用的错误消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,当您使用无效的URL调用WinJS.xhr时,将使用XHR对象调用错误处理程序。但是我们无法打印出错误的原因,因为XHR对象本身不携带此信息。

Currently when you call WinJS.xhr with an invalid URL the error handler will be called with the XHR object. However we have no way to print out the reason for the error as the XHR object itself does not carry this information with it.

所有xhr都是向控制台输出错误:

All xhr does is to print an error to the console:

SCRIPT7002:XMLHttpRequest:网络错误0x2ee7,由于错误00002ee7无法完成操作。

文件:default.html

SCRIPT7002: XMLHttpRequest: Network Error 0x2ee7, Could not complete the operation due to error 00002ee7.
File: default.html

如何在应用程序中捕获此错误?

How to catch this error in the app?

推荐答案

嗨!

你试过这个:

WinJS.xhr(options).done(
        function completed(request) {
            // handle completed download.
        }, 
        function error(request) {
            // handle error conditions.
        }, 
        function progress(request) {
            // report on progress of download.
        }
    });


问候!

Regards!


这篇关于如何在WinJS.xhr无法连接时打印有用的错误消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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