473,403 Members | 2,359 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,403 software developers and data experts.

Trying to get xml data using AJAX function getDatafromXml in script

I can get the text file data from Apache but not the xml file data. Both files are in the same place on C:\xampp\htdocs\mdata. The code for the xml data is this:




Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html> <html> <head> <title>Ajax Lesson</title> <script>
  2.         function getDataFromXml(){
  3.         var xmlhttp;
  4.         if(window.XMLHttpRequest){
  5.             xmlhttp = new XMLHttpRequest();
  6.  
  7.         } else{
  8.             xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  9.  
  10.         }
  11.             xmlhttp.onreadystatechange=function(){
  12.             if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
  13.                 xmldata = xmlhttp.responseXML;
  14.                 var movies = xmldata.getElementsByTagName("movie");
  15.                 var output="";
  16.                 output += movies[0].getElementsByTagName('title')[0].firstChild.nodeValue;
  17.                 document.getElementById("data").innerHTML = output;
  18.             }
  19.         }
  20.         xmlhttp.open("GET","movies.xml", true);
  21.         xmlhttp.send();
  22.  
  23.         }
  24.  
  25.     </script> </head> <body> <div id="data"><h2>Replace this text</h2></div> <button type="button" onclick="getDataFromXml()">Get Data</button> </body> </html>
Jun 25 '14 #1
2 1434
Dormilich
8,658 Expert Mod 8TB
the posted code is of the HTML page, not of the XML but that’s not really the point.

open your browser’s developer tools and check in the network section what response the AJAX call receives.
Jun 26 '14 #2
The GET method has a status of 200! Guess that good!
Jul 14 '14 #3

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

Similar topics

1
by: malborg | last post by:
I have simple form in PHP with two input types as text to input login name and password.PS: They use POST method. (index.php) The other script(logowanie.php) checks if login and password is...
2
by: shivendravikramsingh | last post by:
hi friends, i m using a ajax function for retrieving some values from a database table,and display the values in required field,my prob is that the ajax function i m using is working f9 once,but if...
20
by: vjayis | last post by:
hi when i m trying to fetch data from one page to another page using ajax, i get an error message in IE., but it runs well in firefox., could anyone help me., here is my javascript code., ...
17
by: Shalini Bhalla | last post by:
i have 2 tables bank master and branch details having bankcode as a common feild . i have designed a form in which i am filtering branches according to a particular bank code using ajax ,...
1
by: ghjk | last post by:
I'm developing web application using php. In there i want to refresh one of my table which is having mysql data, using ajax. How can I do that? I didn't know anything about ajax and could you please...
18
by: vetrib2w | last post by:
Hi , In short: How to change the form action attribute value using javascript and that need to supported in IE also ? BRIEF: I am using ajax function to submit the form. I am also...
4
by: BaseballGraphs | last post by:
Hello, I am trying to update data on my webpage using AJAX. The idea is when a user clicks a checkbox the data will be updated. This is the code that I have so far: <script...
0
by: BaseballGraphs | last post by:
Hello, I am trying to use Ajax in order to improve the speed of my website. I am trying to pull data from a dynamic page and insert the data onto the current page. There are 3 three things I am...
2
by: heybobo | last post by:
Hi, my aim is to display the content of my json data i receive from my php file. php is sending : PHP---> $arr = array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5);
0
by: karimkhan | last post by:
I have created php code which shows google chart when page is loaded using mysql data and php. I want ajax_form_temp.php has button on which one click then chart should appear without page load using...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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.