阿贾克斯jqXHR.status == 0修复错误 [英] Ajax jqXHR.status==0 fix error

查看:659
本文介绍了阿贾克斯jqXHR.status == 0修复错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 $.ajax({
         url: urlString,
         dataType: "json",
         type: "GET",
         success: function (data) {
             alert(data);
         },
         error: function (jqXHR, exception) {
             if (jqXHR.status === 0) {
                 alert('Not connect.\n Verify Network.');
             } else if (jqXHR.status == 404) {
                 alert('Requested page not found. [404]');
             } else if (jqXHR.status == 500) {
                 alert('Internal Server Error [500].');
             } else if (exception === 'parsererror') {
                 alert('Requested JSON parse failed.');
             } else if (exception === 'timeout') {
                 alert('Time out error.');
             } else if (exception === 'abort') {
                 alert('Ajax request aborted.');
             } else {
                 alert('Uncaught Error.\n' + jqXHR.responseText);
             }

         }
     });

这是利用即时通讯来访问服务器的一些信息,我的JavaScript文件。该urlString提供和正确。我所做的就是下载的,我是检索服务器的.json并在本地计算机上访问它。当我去到从服务器访问文件我不断收到jqXHR.status == 0错误。我不知道如何解决这个问题,因为我看不出什么毛病我code。

This is my javascript file that im using to access some information from a server. The urlString is supplied and is correct. What I did was download the .json from the server that I was retrieving and accessed it locally on my computer. When I go to access the file from the server I keep getting jqXHR.status==0 error. I'm not sure how to fix that because I can't see anything wrong with my code.

有人点我在正确的方向来解决我的错误?

Can someone point me in the right direction to fix my error?

推荐答案

,你得到不同的状态codeS的是,该文件是不与 HTTP牵强的理由:协议,但与文件:的协议。这是自然的,不同的协议有不同的状态codeS。

The reason that you get different status codes is that the file isn't fetched with the http: protocol but with the file: protocol. It's natural that different protocols have different status codes.

您只需要有不同的行为取决于你在哪里获取的文件。

You simply need to have different behaviour depending on where you fetch the file from.

有一个这个,其中被标记为无效的Mozilla bug报告因为这被认为是正确的结果。

There is a Mozilla bug report about this, which is marked as invalid because this is considered to be the correct result.

这篇关于阿贾克斯jqXHR.status == 0修复错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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