weixin_33744141 2014-05-22 09:12 采纳率: 0%
浏览 246

Ajax 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.
 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.
' + jqXHR.responseText);
             }

         }
     });

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?

  • 写回答

2条回答 默认 最新

  • weixin_33734785 2014-05-22 09:28
    关注

    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.

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

    评论

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀