1

如何在 javascript 上的虚假链接上执行 HTTPget 响应代码?

我真的不知道 HTTP 响应代码是什么以及用于什么。

4

2 回答 2

0

使用 javascript 检查 http 状态代码

$(function() {
  var url = "some_url";
  $.ajax(url,
  {
     statusCode: {
     404: function() {
        alert('page not found');
     }
  }).done(function( msg ) {
     alert( "Data Saved: " + msg );
  });
});  

有关这些含义的详细信息,请参见http://en.wikipedia.org/wiki/List_of_HTTP_status_codes

于 2014-05-27T03:52:39.787 回答
0

你也可以试试这个方法

$( document ).ready(function() {
  var url = "/customers/customer_list";
  $.ajax({url:url,
    data: { name: "John", location: "Boston" }
    type: "GET",
    dataType: "html"
    success:function(result){
      alert(result);
    }});
}});    
于 2014-05-27T06:44:29.317 回答