chobo2 Posted August 13, 2007 Share Posted August 13, 2007 Hi I am trying to modify some code but their is one thing that is still getting to me. I don't know where the actual writing of the code happens. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="en" dir="ltr"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>My Music AJax example</title> <script type="text/javascript"><!-- function ajaxRead(file){ var xmlObj = null; if(window.XMLHttpRequest){ xmlObj = new XMLHttpRequest(); } else if(window.ActiveXObject){ xmlObj = new ActiveXObject("Microsoft.XMLHTTP"); } else { return; } xmlObj.onreadystatechange = function(){ if(xmlObj.readyState == 4){ var songs = xmlObj.responseXML.getElementsByTagName('song_name'); for(var i = 0; i < songs.length; i++) { updateObj('xmlObj', songs[i].firstChild.data); } } } xmlObj.open ('GET', file, true); xmlObj.send (''); } function updateObj(obj, data){ document.getElementById(obj).firstChild.data = data; } //--></script> </head> <body> <h1>Viewing my Music with AJAX</h1> <p>This page uses AJax to see a couple of my songs.</p> <p id="xmlObj"> <a href="../../lec 9 & 10/Lesson9 - DOM - SAX - AJAX/ajax/data.xml" title="View the XML data." onClick="ajaxRead('data.xml'); this.style.display='none'; return false">View my Music.</a> </p> </body> </html> like I added that for loop in xmlObj.readyState if statement because I want it to grab all the elements of the xml document after it grabs each one I want it to print it out. What is happening right now it is just going through them all and grabbing the last one in the documents. So I am not sure where I should be altering the code so it prints out after each time. Thanks Link to comment https://forums.phpfreaks.com/topic/64724-need-help-with-this-ajax/ Share on other sites More sharing options...
chobo2 Posted August 13, 2007 Author Share Posted August 13, 2007 I figured it out expect now I don't know to make each one go on its own line. I tried \n but that seems not to be working. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="en" dir="ltr"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>My Music AJax example</title> <script type="text/javascript"><!-- function ajaxRead(file){ var xmlObj = null; if(window.XMLHttpRequest){ xmlObj = new XMLHttpRequest(); } else if(window.ActiveXObject){ xmlObj = new ActiveXObject("Microsoft.XMLHTTP"); } else { return; } xmlObj.onreadystatechange = function(){ if(xmlObj.readyState == 4){ var songs = xmlObj.responseXML.getElementsByTagName('song_name'); for(var i = 0; i < songs.length; i++) { updateObj('xmlObj', songs.firstChild.data); } } } xmlObj.open ('GET', file, true); xmlObj.send (''); } function updateObj(obj, data){ document.getElementById(obj).firstChild.data += data; } //--></script> </head> <body> <h1>Viewing my Music with AJAX</h1> <p>This page uses AJax to see a couple of my songs.</p> <p id="xmlObj"> <a href="../../lec 9 & 10/Lesson9 - DOM - SAX - AJAX/ajax/data.xml" title="View the XML data." onClick="ajaxRead('data.xml'); this.style.display='none'; return false">View my Music.</a> </p> </body> </html> Link to comment https://forums.phpfreaks.com/topic/64724-need-help-with-this-ajax/#findComment-322783 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.