Every time I execute this file, the code runs smoothly until it reaches the point where the send function is triggered. However, the send function only works if there is an alert function directly following it. If I remove the alert("sent"), it gives me a response of ServerReadyState
is:1.
I'm puzzled by this issue and would appreciate any help. I've tested it both on my local machine and personal server, but encountered the same problem consistently.
Here is the snippet of the problematic code:
/**
* @author d
*/
var xhr;
function getPlants(xhr) {
try {
xhr = new XMLHttpRequest();
} catch (microsoft) {
try {
xhr = new ActiveXObject("Msxml2.XMLHTTP");
} catch (othermicrosoft) {
try {
xhr = new ActiveXObject("Microsoft.XMLHTTP");
} catch (failed) {
xhr = false;
alert("ajax not supported");
}
}
}
xhr.open("GET", "db_interactions.php", true);
xhr.send(null);
alert("sent"); //the send function only works if this alert functions is here
if (xhr.readyState == 4) {
return xhr.responseText;
} else {
alert("Server ReadyState is:" + xhr.readyState);
xhr.abort();
//getPlants(xhr);
}
}