Having some difficulty with my JavaScript code calling PHP. Can someone find an error in this code snippet? I'm sure I've used similar code elsewhere on the site...
var xmlHttp = createXmlHttpRequestObject();
var favSongArray = [];
function createXmlHttpRequestObject() {
var xmlHttp;
try {
xmlHttp = new XMLHttpRequest();
} catch (e) {
var XmlHttpVersions = [
"MSXML2.XMLHTTP.6.0",
"MSXML2.XMLHTTP.5.0",
"MSXML2.XMLHTTP.4.0",
"MSXML2.XMLHTTP.3.0",
"MSXML2.XMLHTTP",
"Microsoft.XMLHTTP"
];
for (var i = 0; i < XmlHttpVersions.length && !xmlHttp; i++) {
try {
xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
} catch (e) {}
}
}
if (!xmlHttp) {
alert("Error creating the XMLHttpRequest object.");
} else {
return xmlHttp;
}
}
function process() {
if (xmlHttp) {
alert("Server is available");
try {
xmlHttp.open("GET", "php/getUntimed.php", true);
xmlHttp.onreadystatechange = function(){handleRequestStateChange();};
alert("Attempted to call p_handleRequestStateChange_test");
xmlHttp.send(null);
} catch (e) {
alert("Can't connect to server: \n" + e.toString());
}
}
}
function handleRequestStateChange() {
if (xmlHttp.readyState == 4) {
if (xmlHttp.status == 200) {
try {
u_handleServerResponse();
} catch (e) {
alert("Error reading the response: " + e.toString());
}
} else {
alert("There was a problem retrieving the data:\n" + xmlHttp.statusText);
}
}
}
function u_handleServerResponse() {
var response = xmlHttp.responseText;
favSongArray = response.split("+");
alert("Reached this point");
}
The process() function is triggered by onSubmit. I keep getting a status of zero from xmlHttp. Any insights? Thanks.