Click to See Complete Forum and Search --> : AJAX and PHP


zebdaag
11-28-2006, 09:43 AM
Hi i'm trying to make a website with ajax. This is what i have:

//javascript
//AJAX
var XMLHttpRequestObject = false;

if (window.XMLHttpRequest) {
XMLHttpRequestObject = new XMLHttpRequest();
} else if (window.ActiveXObject) {
XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
}

function getData(dataSource, divID){
if(XMLHttpRequestObject) {
var obj = document.getElementById(divID);
XMLHttpRequestObject.open("GET", dataSource);

XMLHttpRequestObject.onreadystatechange = function()
{
if (XMLHttpRequestObject.readyState == 4 &&
XMLHttpRequestObject.status == 200) {
obj.innerHTML = XMLHttpRequestObject.responseText;
}
}

XMLHttpRequestObject.send(null);
}
}

when i call this:

getData('pages/menu.php','mainMenu');


the information that is output at the php page menu.php is shown in mijn DIV mainMenu works great....but what to do when i want to send information to multiple DIV's so the file menu.php sends one part of information to my DIV mainMenu and another part of information to the DIV subMenu is this possible????

thanks in advance!!
Zeb

Sid3335
11-28-2006, 10:12 AM
is the div subMenu nested within the mainMenu?

if it is you can just generate the code for the submenu on the server side.

if it isn't you could just use a delimiter and echo back the two sections (main and sub).

so if you retreive:

CODE_FOR_MAIN--delimiter--CODE_FOR_SUB

then just split using the delimter, then update each div with the values (split array).

zebdaag
11-28-2006, 10:14 AM
nope

Sid3335
11-28-2006, 10:21 AM
split like this:


update = response.split('--delimiter--');
mainMenu.innerHTML.innerHTML = update[0];
subMenu.innerHTML.innerHTML = update[1];