|
|
|
|
|
|
|
Making Multiple Simultaneous Requests with AJAX in JavaScript
|
To reflect the current status, we can change the contents of the relevant <span>, or in this case change its appearance with CSS:
switch (bits[0]) {
case 'AVAILABLE':
element = document.getElementById('check_'+bits[1]);
element.innerHTML = '<a href="server_admin.php?server='+bits[1]+'" style="color:green" title="Server Admin">'+element.innerHTML+'</a>';
break;
case 'UNAVAILABLE':
document.getElementById('check_'+bits[1]).style.color = 'red';
document.getElementById('check_'+bits[1]).title = 'Unavailable';
break;
case 'TIMEOUT':
document.getElementById('check_'+bits[1]).style.color = 'purple';
break;
}
That's pretty much all we need to do in this function. We can close the if statement, and add code to handle anything other than a HTTP 200 response:
} else {
alert(ajaxArray[index].status);
}
There is one important thing left to do in this function before we're all done with it, and that is free the AJAX object so it can be reused for subsequent requests:
ajaxArray[index] = null;
}
}
} |
|
1 2 3 |
|
|
|
|
|
|