Ajax - Can you load data into two divs same time?
Posted: Fri Jun 13, 2008 6:07 pm
news.php:
js file:
newsLinkAjax.php file process the data and prints the news description in "newsDes" Div. Just wondering how would you load two sets of data in two different divs when the user click on the news title link.
I want the comments made on that particular news to appear in another div and for that i have to retain the newsid. Also there is a submit form for new comments to make. Finding it difficult to solve. Any help?
Code: Select all
echo "<a class=textLink href=# onclick=processNewsLink(".$id.");>*".$title."</a><br/>";
Code: Select all
function processNewsLink(name)
{
//var name = name;
//alert(name);
// proceed only if the xmlHttp object isn't busy
if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
{
// retrieve the name typed by the user on the form
//name = encodeURIComponent(document.getElementById("myName").value);
// execute the quickstart.php page from the server
xmlHttp.open("GET", "newsLinkAjax.php?name=" + name, true);
// define the method to handle server responses
xmlHttp.onreadystatechange = handle;
// make the server request
xmlHttp.send(null);
}
else
// if the connection is busy, try again after one second
setTimeout('processNewsLink()', 1000);
}
// executed automatically when a message is received from the server
function handle()
{
// move forward only if the transaction has completed
if (xmlHttp.readyState == 4)
{
// status of 200 indicates the transaction completed successfully
if (xmlHttp.status == 200)
{
// update the client display using the data received from the server
document.getElementById("newsDes").innerHTML=xmlHttp.responseText
// restart sequence
//setTimeout('process(name)', 1000);
}
// a HTTP status different than 200 signals an error
else
{
alert("There was a problem accessing the server: " + xmlHttp.statusText);
}
}
}
I want the comments made on that particular news to appear in another div and for that i have to retain the newsid. Also there is a submit form for new comments to make. Finding it difficult to solve. Any help?