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 7 of 7
  1. #1
    Regular Coder
    Join Date
    Apr 2012
    Posts
    104
    Thanks
    27
    Thanked 2 Times in 2 Posts

    Question Working in some places, not working in browsers completely...

    Okay, so i was using w3schools and then i found this example, and it was working perfectly fine in their tryit editor, so i thought i would download the files, so i copied all the html written there and made a file and downloaded xml file, this is that example (in their tryit editor):

    http://www.w3schools.com/ajax/tryit....ax_responsexml

    and this is the xml file they are using:

    http://www.w3schools.com/ajax/cd_catalog.xml

    but when i tried to run them on my pc, they didnt work as they had worked in tryit editor, also they were working perfectly fine in live view mode of dreamweaver, i have checked filenames and have kept them in same folder, so can i know why is it not working?

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,197
    Thanks
    23
    Thanked 605 Times in 604 Posts
    The xml file should be named cd_catalog.xml. In the same folder as the calling HTML. And look like this
    Code:
    <CATALOG>
    	<CD>
    		<TITLE>Empire Burlesque</TITLE>
    		<ARTIST>Bob Dylan</ARTIST>
    		<COUNTRY>USA</COUNTRY>
    		<COMPANY>Columbia</COMPANY>
    		<PRICE>10.90</PRICE>
    		<YEAR>1985</YEAR>
    	</CD>
    	<CD>
    		<TITLE>Hide your heart</TITLE>
    		<ARTIST>Bonnie Tyler</ARTIST>
    		<COUNTRY>UK</COUNTRY>
    		<COMPANY>CBS Records</COMPANY>
    		<PRICE>9.90</PRICE>
    		<YEAR>1988</YEAR>
    	</CD>
    ...........
    Should work.

  • #3
    Regular Coder
    Join Date
    Apr 2012
    Posts
    104
    Thanks
    27
    Thanked 2 Times in 2 Posts
    Nop, dosent. works only when uploaded

  • #4
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,197
    Thanks
    23
    Thanked 605 Times in 604 Posts
    It works on my confuser so the problem must be in the differences.
    I store the files in WAMP and use FireFox to call the HTML program.
    My HTML is http://localhost/TestPrograms/test.html and the XML file is http://localhost/TestPrograms/cd_catalog.xml.

    I did try to display the xml file when both were out of WAMP; like in the C: directory or on the desktop or in a folder in Program Files and it does not work, Probably because the HTML file uses AJAX. So I conclude a server is needed. What server are you using?

  • #5
    Regular Coder
    Join Date
    Apr 2012
    Posts
    104
    Thanks
    27
    Thanked 2 Times in 2 Posts
    i have downloaded wamp, now what?

  • #6
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,197
    Thanks
    23
    Thanked 605 Times in 604 Posts
    I have played with this off and on over the weekend. Wish I had a different explanation, but I don't. The xmlhttp.status==200 part of the onreadystatechange part of the code tells us that the server has processed the request and it was successful. My best guess is that is not being sent if your not in a server. Anyway just remove it.
    Change:
    Code:
    if (xmlhttp.readyState==4 && xmlhttp.status==200)
    To:
    Code:
    if (xmlhttp.readyState==4)
    And it should work everywhere.

    WAMP = Go ahead and install it. Lets you check out your coding on your computer.

  • #7
    Regular Coder
    Join Date
    Aug 2010
    Posts
    970
    Thanks
    19
    Thanked 212 Times in 210 Posts
    this works on your file
    system without a server


    Code:
    <!DOCTYPE html>
    <meta http-equiv="content-type" 
    content="text/html;charset=utf-8" />
    <title></title>
    <script type="text/javascript">
    if(window.ActiveXObject) req = new ActiveXObject('MSXML2.XMLHTTP');
    else req = new XMLHttpRequest;
    
    req.open("GET","testXML.xml",false);
    req.send(null);
    
    
    	if (window.DOMParser)	{
      		parser=new DOMParser();
      		xmlDoc=parser.parseFromString(req.responseText,"text/xml");
      	} else {
      		xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
      		xmlDoc.async=false;
      		xmlDoc.loadXML(req.responseText);
      	}  	
    
    
    alert(xmlDoc.getElementsByTagName("age")[0].firstChild.nodeValue)
    </script>
    </head>
    <body>
    
    </body>
    </html>


  •  

    Posting Permissions

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