jquery - 从此 ajax 调用获取 http 状态

标签 jquery ajax http variables http-status

我对 ajax 和 jquery 非常陌生,所以请耐心等待。我目前正在构建一个小型应用程序,它将执行告诉您网站状态代码的基本任务,并根据返回的代码执行某些操作。我在网上找到了这段代码,如果http状态码是404,它会返回“找不到页面”。

$(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/

关于jquery - 从此 ajax 调用获取 http 状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19897866/

相关文章:

javascript - CoffeeScript 不适用于 Rails 4 应用程序中的下拉菜单

javascript - 当我单击按钮时显示隐藏 div onclick jquery 缓慢

javascript - 如何存储来自ajax请求的信息

c++ - 如何使用c++使用http发送文件

javascript - 根据所选框单击提交按钮时网址未打开

javascript - 使用 jQuery 在 div 之间导航

javascript - 如何将数据从 js POST 到 laravel 中 Controller 以外的 php 脚本

javascript - 如何清除单选按钮?

java - 将域分配给 IP 地址

java - CLOSE_WAIT 中的 Jetty 连接未关闭