Jus*_*808 10 javascript apache ajax jquery http
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);
}
});
});
Run Code Online (Sandbox Code Playgroud)
PHP
header("HTTP/1.0 200 Some message here");
flush();
exit();
Run Code Online (Sandbox Code Playgroud)
结果
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
Run Code Online (Sandbox Code Playgroud)
题
如何获得标题中的"此处的一些消息"部分?
HTTP
6.1状态线
响应消息的第一行是状态行,由协议版本后跟数字状态代码及其关联的文本短语组成,每个元素由SP字符分隔.除最终的CRLF序列外,不允许使用CR或LF.
Run Code Online (Sandbox Code Playgroud)Status-Line = HTTP-Version SP Status-Code SP Reason-Phrase CRLF
知道了。它是jqXHR.statusText。
$.get("test.php").complete(function(jqXHR) {
console.log(jqXHR.statusText);
});
Run Code Online (Sandbox Code Playgroud)
只需在 Chrome 中使用您的确切 PHP 代码进行尝试即可。
| 归档时间: |
|
| 查看次数: |
6491 次 |
| 最近记录: |