Hello all,
I have a weird issue here. This chunk of code used to work, but no matter what I try, I just can't get it to work again.
Basically, the AJAX response receives a string, the following is an example:
"1,5,5,1;2,5,5,1;3,5,5,1"
So then I split the string by ";" and get an array filled like the following:
array[0] = "1,5,5,1";
array[1] = "2,5,5,1";
array[2] = "3,5,5,1";
Then I split each string by "," within the array to get the following two-dimensional array:
array[0][0] = "1"; //An ID number
array[0][1] = "5"; //A Rating out of 5
array[0][2] = "5"; //A Counter
array[0][3] = "1"; //True or False (ie. 1 or 0)
Now here's the code.
xmlhttpx = CrossXHR();
response = "";
if (xmlhttpx == null)
{
alert ("Your browser does not support AJAX!");
return;
}
stars = new Array(5);
var url = "http://www.pmlegion.com/Bb61d320F431e28DaAc4C8768f7563Dc/ajax/checkRatings.php";
var param = "id=" + "garbage";
xmlhttpx.open("POST",url,true);
xmlhttpx.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttpx.setRequestHeader("Content-length", param.length);
xmlhttpx.setRequestHeader("Connection", "close");
xmlhttpx.onreadystatechange = stateChanged;
xmlhttpx.send(param);
function stateChanged()
{
if (xmlhttpx.readyState==4)
{
response = xmlhttpx.responseText;
if (response != "") {
responseOne = response.split(";");
responseTwo = new Array(responseOne.length);
for (i = 0; i < responseOne.length;i++) {
responseTwo[i] = new Array(4);
}
for (i = 0; i < responseOne.length; i++) {
responseTwo[i] = responseOne[i].split(",");
}
for (i = 0; i < responseTwo.length; i++) {
starCtrOne = 0;
starCtrTwo = 0;
rateCtr = document.getElementById("starCount_"+responseTwo[i][0]);
rateCtr.innerHTML = responseTwo[i][2];
for (j = 0; j < stars.length; j++) {
starCtrOne = j + 1;
stars[j] = document.getElementById("star_"+responseTwo[i][0]+"_"+starCtrOne);
}
for (j = 0; j < 5; j++) {
starCtrTwo = j + 1;
if (starCtrTwo <= responseTwo[i][1]) {
[B]stars[j].src = "star_full.png";[/B]
} else {
stars[j].src = "star_empty.png";
}
if (responseTwo[i][3] == 1) {
stars[j].onmouseover = '';
stars[j].onclick = '';
stars[j].style.cursor = 'default';
}
}
}
}
}
}
function CrossXHR()
{
var crossxhr = false;
if(window.XMLHttpRequest) {
crossxhr = new XMLHttpRequest();
if(crossxhr.overrideMimeType) {
crossxhr.overrideMimeType('text/xml');
}
} else if (window.ActiveXObject) {
try {
crossxhr = new ActiveXObject('Msxml2.XMLHTTP');
} catch(e) {
try {
crossxhr = new ActiveXObject('Microsoft.XMLHTTP');
} catch(e) {
crossxhr = false;
}
}
}
return crossxhr;
}
I even used FireBug to set a breakpoint and step through the code. So if you'll notice, I highlighted one line of code in red. When "i" reaches 3 and "j" reaches 2, the FOR LOOP just stops. No errors or anything.
Please let me know if you need anymore information.
Thanks,
Zurom