Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Updating individual cells with AJAX

I was wondering if there was a method to update a cell in a table that had a unique id? Something with <td id="xxxxx"></td> or in a <div> tag. The table will have hundreds of cells.

Here is my quick and dirty code (stolen from here (http://www.dynamicajax.com/fr/AJAX_Hello_World-271_290_322.html) ):

function getXmlHttpRequestObject() {
if (window.XMLHttpRequest) {
return new XMLHttpRequest();
} else if(window.ActiveXObject) {
return new ActiveXObject("Microsoft.XMLHTTP");
} else {
alert("Your browser doesn't support the XmlHttpRequest object. Better upgrade to Firefox.");
}
}

var receiveReq = getXmlHttpRequestObject();

function sayHello() {
if (receiveReq.readyState == 4 || receiveReq.readyState == 0) {
receiveReq.open("GET", 'SayHello.html', true);
receiveReq.onreadystatechange = handleSayHello;
receiveReq.send(null);
}
}

function handleSayHello() {
if (receiveReq.readyState == 4) {
document.getElementById('span_result').innerHTML = receiveReq.responseText;
}
}

The way I'm trying to do it is pass a variable into the "handleSayHello" function so it would change the element ID that matches the variable (or "the individual cell"). When I try that nothing happens. Thanks.
[1392 byte] By [lindenmj] at [2007-11-11 10:30:19]