473,408 Members | 2,839 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

cannot load data from xml file, html not affected

my ajax function is triggered on window.load but it doesn't affect html at all. Here's my ajax:

Expand|Select|Wrap|Line Numbers
  1. function titleTopic(url)
  2. {
  3. var xmlhttp;
  4. var txt,txt2,xxx,xx,x;
  5. if (window.XMLHttpRequest)
  6.   {// code for IE7+, Firefox, Chrome, Opera, Safari
  7.   xmlhttp=new XMLHttpRequest();
  8.   }
  9. else
  10.   {// code for IE6, IE5
  11.   xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  12.   }
  13. xmlhttp.onreadystatechange=function()
  14.   {
  15.   if (xmlhttp.readyState==4 && xmlhttp.status==200)
  16.     {
  17.     x=xmlhttp.responseXML.documentElement.getElementsByTagName("ARTICLE");
  18.  
  19.       xx=x[0].getElementsByTagName("TITLE");
  20.       txt=xx[0].firstChild.nodeValue;
  21.       xxx=x[0].getElementsByTagName("AUTHOR");
  22.       txt2=xxx[0].firstChild.nodeValue;
  23.  
  24.  
  25.     document.getElementByTagName('h3').innerHTML=txt;
  26.     document.getElementByTagName('span').innerHTML=txt2;
  27.     }
  28.   }
  29. xmlhttp.open("GET",url,true);
  30. xmlhttp.send();
  31. }
Jan 13 '14 #1
10 2766
Rabbit
12,516 Expert Mod 8TB
How do you know it triggers?

On line 25 and 26, it's getElementsByTagName, not getElementByTagName.
Jan 13 '14 #2
Yeah ive changed the code but it still doesn't work, ive runthe website on google console and the errors ive got are
Uncaught SyntaxError: Unexpected end of input for line 1 of moje.js
Uncaught ReferenceError: process is not defined for line 71 of webdesign.html which is basically the button with process() function

So it's basically the first line of my javascript file: var xmlHttp = createXmlHttpRequestObject();
and then a button that triggers my function in html

my full ajax:
Expand|Select|Wrap|Line Numbers
  1. var xmlHttp = createXmlHttpRequestObject();
  2.  
  3. //create object
  4. function createXmlHttpRequestObject() {
  5.     var xmlHttp;
  6.     if (window.XMLHttpRequest){
  7.         xmlHttp = new XLHttpRequest();
  8.     } else {
  9.         xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  10.     }
  11.     return xmlHttp;
  12. }
  13.  
  14. //called onload
  15.  
  16. function process() {
  17.     if(xmlHttp) {
  18.         try{
  19.             xmlHttp.open("GET", "C:/xampp/htdocs/webdesign.xml", true);
  20.             xmlHttp.onreadystatechange = handleStateChange;
  21.             xmlHttp.send(null);
  22.         }
  23.         catch(e) {
  24.             alert(e.toString());
  25.         }
  26. }
  27.  
  28. //when state changes
  29. function handleStateChanges() {
  30.     if (xmlHttp.readyState==4) {
  31.         if(xmlHttp.status==200) {
  32.             try {
  33.                 handleResponse();
  34.  
  35.             }
  36.             catch(e) {
  37.                 alert(e.toString());
  38.             }
  39.         } else {
  40.             alert(xmlHttp.statusText);
  41.         }
  42.     }
  43. }
  44.  //handle the response from the server
  45.  function handleResponse() {
  46.     var xmlResponse = xmlHttp.responseXML;
  47.     root = xmlResponse.documentElement;
  48.     articles = root.getElementsByTagName("TITLE");
  49.     authors = root.getElementsByTagName("AUTHOR");
  50.  
  51.     var stuff = "";
  52.     for (var i=0; i<articles.length; i++) {
  53.         stuff = articles.item(i).firstChild.data + " - " + authors.item(i).firstChild.data + "<br/>";
  54.  
  55.     }
  56.     super2 = document.getElementByID("super2");
  57.     super2.innerHtml = stuff;
  58.  }
  59.  
  60.  
and the mentioned html
Expand|Select|Wrap|Line Numbers
  1.         <article id='super2'>
  2.         <button onclick="process()">Get XML data</button>
  3.  
  4.         </article>
Jan 13 '14 #3
Rabbit
12,516 Expert Mod 8TB
The first error that jumps out at me is that on line 7 of your javascript code block, XLHttpRequest should be XMLHttpRequest
Jan 13 '14 #4
oh you're right, fixed it but it still doesn't work
I'm using xampp but ajax is just ignored other javascript works just fine.
Still im getting the same error from the console
Uncaught ReferenceError: process is not defined webdesign.html:71
onclick
Jan 13 '14 #5
ok, i kind of made stupid mistake and fixed it, i lacked one curly bracket that's it and started getting error alerts
but i get an error from xml I found it and fixed it but it's still the same:
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="ISO-8859-1"?>
  2. <!-- Edited by XMLSpy® -->
  3. <RESPONSE>
  4.     <TOPICS>
  5.         <ARTICLE>
  6.             <TITLE>The Lean UX Manifesto: Principle-Driven Design</TITLE>
  7.             <AUTHOR>Anthony Viviano</AUTHOR>
  8.             <YEAR>2014</YEAR>
  9.             <TEXT>My colleague Ajay and I have been working at incorporating lean UX at the enterprise level for over two years. In studying it, I find that there is a temptation to lay down rules, and if the rules arent followed. well, then, you cant call it lean UX. At the end of the day, though, some lean UX is better than none.</TEXT>
  10.         </ARTICLE>
  11.         <ARTICLE>
  12.             <TITLE>Killer Responsive Layouts With CSS Regions</TITLE>
  13.             <AUTHOR>CJ Gammon</AUTHOR>
  14.             <YEAR>2013</YEAR>
  15.             <TEXT>As Web designers, we are largely constrained by the layout features available to us. Content placed inside a container will often naturally extend the container vertically, wrapping the content. If a design requires elements to remain a certain height, then our options are limited. In these cases, we can only add a scroll bar or hide the overflow. The CSS Regions specification provides a new option.</TEXT>
  16.         </ARTICLE>
  17.         <ARTICLE>
  18.             <TITLE>Original And Innovative Web Layouts</TITLE>
  19.             <AUTHOR>Shavaughn Haack</AUTHOR>
  20.             <YEAR>2013</YEAR>
  21.             <TEXT>The layout is the foundation of your website. It guides the user through the sections and tells them what is most important. It also sets the aesthetic of the website. Therefore, you need to carefully think through how you lay out content.</TEXT>
  22.         </ARTICLE>
  23.     </TOPICS>
  24. </RESPONSE>
XML Parsing Error: mismatched tag. Expected: </AUTHOR>. Location: moz-nullprincipal:{b3ef63a7-15a2-4c24-8903-7e94bdda5807} Line Number 16, Column 5:

</ARTICLE>
------------------^

Probably it's a stupid mistake too oh well..

Thx for your help anyway
Jan 13 '14 #6
it just hasn't updated the file, i fixed it but it's still not displaying anything
Jan 13 '14 #7
Rabbit
12,516 Expert Mod 8TB
Where is the code getting stuck at now? And what's your newly modified code? It sounds like you made more than a few changes.
Jan 13 '14 #8
ok fixed it, i just needed a monologue i guess xD
Jan 13 '14 #9
Rabbit
12,516 Expert Mod 8TB
Can you post your final solution? In case someone else runs into the same issue and stumbles upon this thread.
Jan 13 '14 #10
They were mostly typos of methods and one essential bracket was missing, final version:
Expand|Select|Wrap|Line Numbers
  1. var xmlHttp = createXmlHttpRequestObject();
  2.  
  3. //create object
  4. function createXmlHttpRequestObject() {
  5.     var xmlHttp;
  6.     if (window.XMLHttpRequest){
  7.         xmlHttp = new XMLHttpRequest();
  8.     } else {
  9.         xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  10.     }
  11.     return xmlHttp;
  12. }
  13.  
  14. //called onload
  15.  
  16. function process() {
  17.     if(xmlHttp) {
  18.         try{
  19.             xmlHttp.open("GET", "webdesign1.xml", true);
  20.             xmlHttp.onreadystatechange = handleStateChange;
  21.             xmlHttp.send(null);
  22.         }
  23.         catch(e) {
  24.             alert(e.toString());
  25.         }
  26. }
  27.  
  28. //when state changes
  29. function handleStateChange() {
  30.     if (xmlHttp.readyState==4) {
  31.         if(xmlHttp.status==200) {
  32.             try {
  33.                 handleResponse();
  34.  
  35.             }
  36.             catch(e) {
  37.                 alert(e.toString());
  38.             }
  39.         } else {
  40.             alert(xmlHttp.statusText);
  41.         }
  42.     }
  43. }
  44.  //handle the response from the server
  45.  function handleResponse() {
  46.     var xmlResponse = xmlHttp.responseXML;
  47.     root = xmlResponse.documentElement;
  48.     articles = root.getElementsByTagName("TITLE");
  49.     authors = root.getElementsByTagName("AUTHOR");
  50.  
  51.     var stuff = "";
  52.     for (var i=0; i<articles.length; i++) {
  53.         stuff = "<p>" + articles.item(i).firstChild.data + " - " + authors.item(i).firstChild.data + "</p>";
  54.  
  55.     }
  56.     super2 = document.getElementById("super2");
  57.     super2.innerHTML = stuff;
  58.  }
  59.  
  60. }
  61.  
Jan 13 '14 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: Bruce A. Julseth | last post by:
When I execute this SQL statement in my PHP code, I get an error "File '.\Address.txt' not found (Errcode: 2)" $File = addslashes(".\Address.txt"); $SQL = "Load Data InFile \"" . $File . "\"...
2
by: Alex Hunsley | last post by:
I'm using a mysql monitor under cygwin (on win xp) to do a 'load data infile' to put some data into a mysql database (I'm using the xampp bundle).. My problem is that I have a four line CSV file...
0
by: Kins | last post by:
Hi, In web application, I use listbox in the EditItemTemplate in the Datagrid. But I cannot load data from the database to the Listbox. Is it possible ? Thx a lot regards, Kin
1
by: Ray in HK | last post by:
What are the differences between LOAD DATA INFILE and LOAD DATA LOCAL INFILE ? I found some web hosting company do not allow using LOAD DATA INFILE but allow LOAD DATA LOCAL INFILE. The reason...
1
by: Uthuras | last post by:
Greetings, Machine : Pentium IV Os Windows 2000 server Product : DB2 UDB Release : 7.2 We are fail to load the following data file format into db2 database table that has long varchar...
0
by: thjwong | last post by:
I'm using WinXP with Microsoft Visual C++ .NET 69462-006-3405781-18776, Microsoft Development Environment 2003 Version 7.1.3088, Microsoft .NET Framework 1.1 Version 1.1.4322 SP1 Most developers...
1
by: Adrian Turner | last post by:
I am just starting developing with .Net(Have used asp for years). I have created a very simple upload page which once uploaded opens the file(excel) and displays the data. If I Attempt to re-run...
0
by: Fendi Baba | last post by:
I created an ASP.net page which opens excel. This works fine in Office 2007. However, Excel 2003 runs in an error which states "cannot read output file". Hee is the VB code and below is the ASPX...
1
by: =?Utf-8?B?VGVycmVuY2U=?= | last post by:
For a past day or two I've been to noticing the following error. Event Type: Warning Event Source: Outlook Event Category: None Event ID: 25 Date: 6/24/2007 Time: 12:05:07 PM User: N/A...
1
by: pzero24 | last post by:
Ok so I am making plugins for my application and I have the plugins located in a subdirectory: /AppDir /AppDir/Plugins All my plugins reference a Plugins interface file, which is also located...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.