gpt4 book ai didi

php - Ajax返回HTTP响应501 : method not implemented

转载 作者:太空宇宙 更新时间:2023-11-04 04:19:32 24 4
gpt4 key购买 nike

我请求一个简单的 php 文件来回显一行;使用 AJAX,但我从 Linux 上的本地主机服务器收到 HTTP 501 响应。我的问题是,什么可能导致这种错误?

JavaScript:

var request = new XMLHttpRequest();

request.onreadystatechange = function () {
//console.log(request.responseText);
if (request.readyState == 4 && request.status == 200) {
console.log(0);
} else if (request.status == 501) {
console.log(request.responseText);
}
}
request.open('test.php', 'GET', true);
request.send();

test.php:

<?php echo 'this is a test'; ?>

最佳答案

据了解,在readyState之前你无法检测服务器的状态。如果是 4(即 DONE),则可以检查服务器状态。

因此,在检查status之前,您需要先检查readyState

if (req.readyState === 4) {
// 200 is not enough to detect successful requests
// cos there are many success status codes
if (req.status === 200) {
// every thing ok
} else {
// something is wrong with server?
}
}

在这里查看 HTTP 状态代码:http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html

也许这对您有用:https://github.com/qeremy/mii/blob/master/mii.ajax.js#L248

关于php - Ajax返回HTTP响应501 : method not implemented,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14447086/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com