So, I am creating a mobile application using Intel XDK, I am sending a POST request for JavaScript with a username and password. I also did some research on HTTP status codes and found this:
200 OK - Standard response for successful HTTP requests. The actual response will depend on the request method used. In a GET request, the response will contain an entity corresponding to the requested resource. In a POST request the response will contain an entity describing or containing the result of the action.
201 Created - The request has been fulfilled and resulted in a new resource being created.
202 Accepted - The request has been accepted for processing, but the processing has not been completed. The request might or might not eventually be acted upon, as it might be disallowed when processing actually takes place.
Therefore, I would suggest that when a new user is inserted through a POST request, the status will be 201. However, when I had this code:
XMLHTTP.onreadystatechange = function () {
if (XMLHTTP.status == 201) {
alert("User created.");
} else {
alert("Error!");
}
}
It will show "Error!". not user created. But when I added this to the code:
XMLHTTP.onreadystatechange = function () {
if (XMLHTTP.status == 201 || XMLHTTP.status == 200) {
alert("User created.");
} else {
alert("Error!");
}
}
He showed "User Created." So I was wondering how to get the status of 200, although I am sending a POST request to be inserted into the database.
-, " ". 4 ? , onreadystatechange, ? , , ? if, setinterval, :
setInterval(function () {
if (XMLHTTP.status == StatusNumberHere) {
alert("Blah");
}
}, 10);