http获取请求状态

时间:2012-02-17 16:09:44

标签: javascript jquery http httpwebrequest xmlhttprequest

我正在使用jQuery发送HTTP请求。下面是代码。我想获取HTTP请求的状态代码。

有谁知道,如何获得状态?

    $(document).ready(function(){
     var url="http://www.google.com";
     $.get(url, function(data,status) {
        alert(status); 
       // This doesn't alert me status           
      // I want to alert request status code as "200" i.e. ok
            });
      // on Failure also need the status code of this request.
    });

1 个答案:

答案 0 :(得分:3)

更新


Working Example


$.get(url, function(data,status, xhr) {
    alert(xhr.status);
});