我对ajax和jquery还很陌生,所以请容忍我。我目前正在构建一个小型应用程序,它将完成告诉您网站状态代码的基本任务,并根据返回的代码执行一些操作。我在网上找到了这个代码,如果http状态代码是404,它会返回“page not found”。

$(function() {
      var url = "http://www.google.com";
      $.ajax(url,
      {
         statusCode: {
         404: function() {
            alert('page not found');
         }
      }
   });
});

但是,如何将原始状态代码值保存到变量中,而不是检查404状态代码?
谢谢!

最佳答案

希望这样的东西能帮到你。:)

 error:function (xhr, ajaxOptions, thrownError){
          alert(xhr.status);
           switch (xhr.status) {
              case 404:
                    // Desired Action.
              }
        }

    complete: function(xhr, statusText){
           alert(xhr.status);
    }

你可以在下面的链接中得到很多信息
http://api.jquery.com/jQuery.ajax/

07-24 09:50
查看更多