I am requesting a simple php file that echos a single line; using AJAX, but I am getting a HTTP 501 response from my localhost server on linux. My question is, What could be causing this kind of error?
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'; ?>
As far as know, you can not detect server the status before
readyState. If it’s4(soDONE) then can check the server status.So you need to check first
readyStatebefore checkingstatus.Have a look HTTP status code here: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
Maybe this could be useful for you: https://github.com/qeremy/mii/blob/master/mii.ajax.js#L248