如何使用jQuery获取HTTP状态代码?

我想检查一个页面是否返回状态码401.这是可能吗?

这里是我的尝试,但它只返回0。

$.ajax({
    url: "http://my-ip/test/test.PHP",data: {},complete: function(xhr,statusText){
    alert(xhr.status); 
    }
});

解决方法

这是可能与jQuery $ .ajax()方法
$.ajax(serverUrl,{
   type: Outageviewmodel.Id() == 0 ? "POST" : "PUT",data: dataToSave,statusCode: {
      200: function (response) {
         alert('1');
         AfterSavedAll();
      },201: function (response) {
         alert('1');
         AfterSavedAll();
      },400: function (response) {
         alert('1');
         bootBox.alert('<span style="color:Red;">Error While Saving Outage Entry Please Check</span>',function () { });
      },404: function (response) {
         alert('1');
         bootBox.alert('<span style="color:Red;">Error While Saving Outage Entry Please Check</span>',function () { });
      }
   },success: function () {
      alert('1');
   },});

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: &lt;span id=&quot...
jQuery 添加水印 &lt;script src=&quot;../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...