如题,要用ajax发送一个请求然后判断响应的状态码做一些操作,如何才能获取状态码?

解决方案 »

  1.   

    Demo:
    $.ajax({
        url: "/echo/xml/",
        type: "POST",
        data: {
            //Set an empty response to see the error
            xml: "<response></response>"   
        },
        dataType:"text xml",
        success: function(xml, textStatus, xhr) {
            console.log(arguments);
            console.log(xhr.status);
        },
        complete: function(xhr, textStatus) {
            console.log(xhr.status);
        } 
    });
      

  2.   

    我做了实验,如果是有错误不是正常返回200,那么xhr.status是error,不是具体的状态码啊