Link to home
Start Free TrialLog in
Avatar of brgdotnet
brgdotnetFlag for United States of America

asked on

Need help reading XML using the browsers XMLHttpRequest object and client side JavaScript request

Can someone help me solve the following problem.  For the URL listed, assume that if you did go to that URL, then the XML will be  displayed in the web page, and it will look like the XML displayed in the "Code:" section of this post.
1. Create an HTML page with three <div>s and a button.
2.Upon clicking the button then using client-side JavaScript requests, get the XML returned from the URL: 
using the browsers XMLHttpRequest object.
3.From the XML returned from the JavaScript request, display the EventTime 
and the Sport for the Sport with the latest post time in the three <div>s
created in the first step.
<?xml version="1.0" encoding="utf-8" ?> 
- <DATA EventTime="9:38:25 PM" ErrorText="" ErrorInt="0" ItemCount="122" >
  <EVENT Greek="Omega" Sport="SWIM" Date="3/2/2009" PostTime="3:25 PM" /> 
  <EVENT Greek="Omega" Sport="RUN"  Date="3/2/2009" PostTime="8:55 PM" /> 
  <EVENT Greek="Omega" Sport="SKI"  Date="3/2/2009" PostTime="4:51 PM" />  
  <EVENT Greek="Omega" Sport="SURF" Date="3/2/2009" PostTime="8:55 PM" /> 
  <EVENT Greek="Omega" Sport="BOWL" Date="3/2/2009" PostTime="5:50 PM"/> 
  <EVENT Greek="Omega" Sport="CYCLE"  Date="3/2/2009" PostTime="7:55 PM"/> 
  <EVENT Greek="Omega" Sport="FISH" Date="3/2/2009" PostTime="2:45 PM"/> 
  <EVENT Greek="Omega" Sport="SKEET" Date="3/2/2009" PostTime="1:55 PM"/> 
  <EVENT Greek="Omega" Sport="SOCCER" Date="3/2/2009" PostTime="3355 PM"/> 

Open in new window

Avatar of Pieter Marais
Pieter Marais
Flag of South Africa image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of brgdotnet


I appreciate your help. I noticed it was not working and so I traced into the code in the debugger. I get an "Access Denied" message when this line of code is executed:'POST', strURL, true);

 That line of code is inside of the function xmlhttpPost(strURL, strQueryString)

Do you have any idea why I am getting that message?
AJAX has this built-in security functionality that prevents you from making requests to a domain other than that on which it is hosted. So if this script, for example, is hosted on, you can't go and make requests to Hence the "Access Denied" message.

If you want to use this script, the file or script that you wish to access with the AJAX must be on the same domain.

There are workarounds though, depending on which system you are using the AJAX. For example, if your system supports PERL, you can use a script that implements the HTTP::Request and LWP::UserAgent modules.

So instead of calling the URL directly, you can use a script on your server that retrieves the information for you for the other domain and then returns it to the AJAX on your domain.
Thanks Buddy!