jQuery and Ajax
Posted
by Banderdash
on Stack Overflow
See other posts from Stack Overflow
or by Banderdash
Published on 2010-05-04T17:20:23Z
Indexed on
2010/05/04
17:28 UTC
Read the original article
Hit count: 257
Can anyone help with a jQuery snippet that would use Ajax to pull an XML file in on page load?
Have really clunky way of doing it without jQuery here:
<script type="text/javascript">
function loadXMLDoc()
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
xmlDoc=xmlhttp.responseXML;
var txt="";
x=xmlDoc.getElementsByTagName("title");
for (i=0;i<x.length;i++)
{
txt=txt + x[i].childNodes[0].nodeValue + "<br />";
}
document.getElementById("checkedIn").innerHTML=txt;
}
}
xmlhttp.open("GET","ajax-response-data.xml",true);
xmlhttp.send();
}
</script>
Ideally rather the having a click generate the list it would do so on page load, showing the fields from the XML (title, author, and whether it is checked in or not i.e. <book id="#" checked-in="0">
)
Would hug you for a solution.
© Stack Overflow or respective owner