I’ve got a simple AJAX app and I have two functions for returning information, one in text and the other in XML. Using the code below I’d have to make a function for each ID that receives data. The functions below create the desired output but see the second version to see what I want them to do.
[code]
function createRequestObject()
{
var request_o; //declare the variable to hold the object.
var browser = navigator.appName; //find the browser name
if(browser == “Microsoft Internet Explorer”){
/* Create the object using MSIE’s method */
request_o = new ActiveXObject(“Microsoft.XMLHTTP”);
}else{
/* Create the object using other browser’s method */
request_o = new XMLHttpRequest();
}
return request_o; //return the object
}
var http = createRequestObject();
function getClientList()
{
// opens the portfolio page and requests the client list
http.open (‘get’, ‘portfolio.php?action=client_list&filename=portfolio.xml&listof=client_name&withExpand=1’);
// calls the client list function defined below
http.onreadystatechange = getResultsText;
// sends the data (null is for the get method)
http.send(null);
}
function getResultsText()
{
if (http.readyState == 4) // finished loading the request
{
var response = http.responseText; // assigns the request as text
document.getElementById(‘client_list’).innerHTML = response; // outputs the information to the ‘client_list’ div
}
}
The code below gives no output. I highlighted in bold the changes to show what I need the function to do.
I’m not terribly familiar with Javascript except for form validation so this is probably something simple.
[code]
function getClientList()
{
// opens the portfolio page and requests the client list
http.open (‘get’, ‘portfolio.php?action=client_list&filename=portfolio.xml&listof=client_name&withExpand=1’);
// calls the client list function defined below
http.onreadystatechange = getResultsText([B]’client_list'[/B]);
// sends the data (null is for the get method)
http.send(null);
}
function getResultsText([B]byId[/B])
{
if (http.readyState == 4) // finished loading the request
{
var response = http.responseText; // assigns the request as text
document.getElementById([B]byId[/B]).innerHTML = response; // outputs the information to the ‘client_list’ div
}
}