Is it possible/do web applications developers ever purposely set/send out a HTTP Status Code, so that it can be better hanled client side by pages utilizing ajax?
Printable View
Is it possible/do web applications developers ever purposely set/send out a HTTP Status Code, so that it can be better hanled client side by pages utilizing ajax?
I'm slightly confused by your question. Do you mean the following?
Sometimes, to make pages smoothly operate, I ignore the status altogether. As long as the readyState is set, most times it will be without error.Code:objXML.status = 200;
Yea, for example error handling, you might handle an exception in your backend code which your javascript doesn't have full visibility of, therefore with your exception you might also send a status code, so that the javascript can be,
It seems sensible, but I don't know if it can be done, or if anyone does it, or if there is any need to.Code:if (xmlhttp.status == mystatus)
{
document.findelementbyid("foo").value="there has been some error";
}
Well, why don't you build a simple AJAX object, and try to set the status. Personally, I don't really find use for it because the status applies to the server page status. Why would you need more than...
Code:if (objXML.status == 200) {alert("Page found.");}
...
else if (objXML.status == 403) {alert("Access denied.");}
else if (objXML.status == 404) {alert("URL not found.");}
...
else {alert("status is " + request.status);}