Alert JQuery Ajax状态代码 [英] Alert JQuery Ajax Status codes

查看:70
本文介绍了Alert JQuery Ajax状态代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Jquery Ajax中如何显示警报错误消息如果由于服务器关闭而未找到/未能加载ajax url。

In Jquery Ajax How Can I show alert error message If the ajax url is not found/failed to load due to server down.

我试过

error:function(){
}

statusCodes:{
}

这些只是工作如果网址是加载成功。如果网址加载失败,我该如何显示错误消息?

Those are working only If url is loaded successfully. If the url is failed to load how can I show error message ?

我正在使用JSONP

推荐答案

您可以使用以下命令检查jQuery ajax返回的所有状态

you can use the following to check all the statuses returned by jQuery ajax

 $.ajax(
   statusCode: {
      200: function (response) {
         alert('status 200');
      },
      201: function (response) {
         alert('status  201');
      },
      400: function (response) {
         alert('status  400');
      },
      404: function (response) {
         alert('status  404 ');
      }
   }, success: function () {
      alert('success');
   },
});

这篇关于Alert JQuery Ajax状态代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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