Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Apr 2012
    Posts
    104
    Thanks
    27
    Thanked 2 Times in 2 Posts

    Exclamation linking html doc to html doc, then accessing info from xml and pasting it in html doc

    Here is my JS code, i am trying to link xml document to html document and accsesing xml data and writing same data in the html file, here is my very simple xml code, i dont know whats wrong but its not doing what it supposed to, when function stuff() is called :
    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <qwe>
     <potter> I am Potter </potter>
    </qwe>
    And here's my javascript:
    Code:
    <script type="text/javascript">
    		if (window.XMLHttpRequest)
    		{
    		xhttp=new XMLHttpRequest();
    		}
    		else // IE 5/6
    		{
    		xhttp=new ActiveXObject("Microsoft.XMLHTTP");
    		}
    		xhttp.open("GET","xmlfile.xml",false,);
    		xhttp.send();
    		xmlDoc=xhttp.responseXML;
    		
    	function stuff()
    	{
    		goo = xmlDoc.getElementsByTagName("potter")[0].childNodes[0].nodeValue;
    		document.getElementById("content").innerHTML = goo;
    	}
    	</script>

  • #2
    Moderator
    Join Date
    May 2002
    Location
    Hayward, CA
    Posts
    1,461
    Thanks
    1
    Thanked 23 Times in 21 Posts
    Where do you tell it to call stuff()? You're dealing with an asynchronous XHR, which means the response could come literally anytime from now to 100 years in the future. (Although I wouldn't bet on the latter.)

    What is it doing wrong, specifically?
    "The first step to confirming there is a bug in someone else's work is confirming there are no bugs in your own."
    June 30, 2001
    author, Verbosio prototype XML Editor
    author, JavaScript Developer's Dictionary
    https://alexvincent.us/blog

  • #3
    Regular Coder
    Join Date
    Apr 2012
    Posts
    104
    Thanks
    27
    Thanked 2 Times in 2 Posts
    i am calling function stuff () when the body loads. Problem i am getting is, in function stuff(), the line
    Code:
     document.getElementById("content").innerHTML = goo;
    Its supposed to write fetched data in the document, but it aint doing so.

    Btw site i am making , its contents have to be updated on a daily basis and a large amount of changes made to the data daily, plus that data is to be used again and again, thats why i chose xml. I am new to xml.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •