...

View Full Version : Asp Xml Ajax



stevanicus
12-27-2007, 02:10 AM
Hi,

I have a simple bloging/comments system that has a form - this form then uses an xmlHttp request, where my asp file extracts data from my database and creates an xml form.

However Im having problems controlling the output of the database. I want it to display everything with is does according to the SQL query. however i might want to display certain things in different ways e.g. bold italic etc.

However it just displays it in one big set and i can touch any of the data.

what am i doing wrong? and what do i need to be looking into?? thanks

stevanicus

AJAX

function blog()
{
var xmlDoc=xmlHttp.responseXML.documentElement;
document.getElementById("tBlog").innerHTML=xmlHttp.responseText;
document.getElementById("bgId").innerHTML=
xmlDoc.getElementsByTagName("blogId")[0].childNodes[0].nodeValue;
document.getElementById("bgbody").innerHTML=
xmlDoc.getElementsByTagName("blogBody")[0].childNodes[0].nodeValue;
document.getElementById("bgmadeBy").innerHTML=
xmlDoc.getElementsByTagName("blogAuthor")[0].childNodes[0].nodeValue;
}

HTML

<div id="tBlog">
<b><span id="bgId"></span></b><br />
<span id="bgbody"></span><br />
<span id="bgmadeBy"></span>
</div>


thanks again

stevanicus
12-27-2007, 12:45 PM
anyone?

A1ien51
12-27-2007, 03:27 PM
If it isXML, you need to use responseXML and loop through the nodes to get out the data.

Eric

stevanicus
12-28-2007, 07:42 PM
Thanks,

i tried that, but then it displays the last record in the xml document.

stevanicus
12-29-2007, 06:21 PM
this is what i added


var xmlDoc=xmlHttp.responseXML.documentElement;
for (i=0; i<=3; i++)
{
document.getElementById("bgId").innerHTML = xmlDoc.getElementsByTagName("blogId")[i].childNodes[0].nodeValue;
document.getElementById("bgbody").innerHTML =xmlDoc.getElementsByTagName("blogBody")[i].childNodes[0].nodeValue;
document.getElementById("bgmadeBy").innerHTML = xmlDoc.getElementsByTagName("blogAuthor")[i].childNodes[0].nodeValue;
}

it then it only displays the last record... i know why, but i dont know how to get it so it doesnt replace the old record just adds it to the bottom of it.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum