Php Ajax返回HTTP响应501:未实现方法
我要求一个简单的php文件,回音一行;使用AJAX,但我从linux上的本地主机服务器获得HTTP 501响应。我的问题是,是什么导致了这种错误 JavaScript:Php Ajax返回HTTP响应501:未实现方法,php,javascript,ajax,linux,apache,Php,Javascript,Ajax,Linux,Apache,我要求一个简单的php文件,回音一行;使用AJAX,但我从linux上的本地主机服务器获得HTTP 501响应。我的问题是,是什么导致了这种错误 JavaScript: var request = new XMLHttpRequest(); request.onreadystatechange = function () { //console.log(request.responseText); if (request.readyState == 4 && r
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:
据我们所知,在
readyState
之前,您无法检测服务器的状态。如果是4
(因此DONE
),则可以检查服务器状态
因此,在检查状态之前,您需要先检查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状态代码:
也许这对你有用:可能是你的代码,你没有发布。如果没有看到你的代码,很难判断。我最近在IIS服务器上使用PUT
和DELETE
时遇到了类似的问题,因为默认情况下不允许使用这些动词。您可能会遇到类似的行为,因为我认为apache(我猜您可能正在使用)也没有自动启用对这些动词的支持。@Musa抱歉,我现在发布了它。。。
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?
}
}