javascript – jquery如何获取ajax调用类型post返回的状态消息?

前端之家收集整理的这篇文章主要介绍了javascript – jquery如何获取ajax调用类型post返回的状态消息?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
JavaScript
$('#send').on('click',function() {
        $.ajax({
            'url': $('#url').val(),'type': 'post','complete': function (jqXHR,textStatus) {
                var msg = "Status: " + jqXHR.status + " (" + jqXHR.statusText + " - " + textStatus + ")<br />";
                msg += jqXHR.getAllResponseHeaders().replace(/\n/g,"<br />");

                $('#results').html(msg);
            }
        });
    });

PHP

header("HTTP/1.0 200 Some message here");
    flush();
    exit();

结果

Status: 200 (OK - success)
Date: Wed,07 Dec 2011 21:57:50 GMT 
X-Powered-By: PHP/5.3.6 
Transfer-Encoding: chunked 
Connection: Keep-Alive 
Server: Apache/2.2.17 (Unix) mod_ssl/2.2.17 OpenSSL/0.9.8r DAV/2 PHP/5.3.6 
Content-Type: text/html 
Keep-Alive: timeout=5,max=100

如何获取“某些消息在这里”部分的标题

HTTP

http protocol

6.1 Status-Line

The first line of a Response message is the Status-Line,consisting of
the protocol version followed by a numeric status code and its
associated textual phrase,with each element separated by SP
characters. No CR or LF is allowed except in the final CRLF sequence.

06003

解决方法

得到它了.它是jqXHR.statusText.
$.get("test.PHP").complete(function(jqXHR) {
    console.log(jqXHR.statusText);
});

只需在Chrome中尝试使用您的确切PHP代码.

原文链接:https://www.f2er.com/ajax/151710.html

猜你在找的Ajax相关文章