jQuery的如何度日的类型后一个AJAX调用返回的状态消息? [英] jquery how to get the status message returned by a ajax call of type post?
本文介绍了jQuery的如何度日的类型后一个AJAX调用返回的状态消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
的javascript
$('#发送)。在('点击',函数(){
$阿贾克斯({
URL:$('#网址)VAL()。
'类型':'后',
完整:功能(jqXHR,textStatus){
VAR味精=状态:+ jqXHR.status +(+ jqXHR.statusText + - + textStatus +)< BR />中;
。MSG + = jqXHR.getAllResponseHeaders()代替(/ \ N /克,< BR />中);
$('#结果)HTML(MSG);
}
});
});
PHP
标题(HTTP / 1.0 200的一些消息,在这里);
冲洗();
出口();
结果
状态:200(OK - 成功)
日期:星期三,2011年12月7日21时57分50秒GMT
的X已启动方式:PHP / 5.3.6
传输编码:分块
连接:保持活动
服务器:Apache / 2.2.17(Unix的)了mod_ssl / 2.2.17的OpenSSL / 0.9.8r DAV / 2 PHP / 5.3.6
内容类型:text / html的
保持活动:超时= 5,最大值= 100
问题
我如何得到一些消息在这里的头的一部分?
HTTP
6.1状态行
一个响应消息的第一行是状态行,由 协议版本后跟数字状态code及其 相应的词语文本,由SP分隔每个元素 字符。 CR或LF是允许的,除了在最后的CRLF序列。
状态行= http版本SP状态 - code SP原因短语CRLF
解决方案
明白了。这是 jqXHR.statusText
。
$。获得(test.php的)。完成(功能(jqXHR){
执行console.log(jqXHR.statusText);
});
只是尝试了一下在Chrome与您确切的PHP code。
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();
Results
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
Question
How do I get the "Some message here" part of the header?
http
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.
Status-Line = HTTP-Version SP Status-Code SP Reason-Phrase CRLF
解决方案
Got it. It's jqXHR.statusText
.
$.get("test.php").complete(function(jqXHR) {
console.log(jqXHR.statusText);
});
Just tried it out in Chrome with your exact PHP code.
这篇关于jQuery的如何度日的类型后一个AJAX调用返回的状态消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文