Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9121293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:49:42+00:00 2026-06-17T05:49:42+00:00

I would like to get the data from the online xml file e.g. http://data.one.gov.hk/others/td/speedmap.xml

  • 0

I would like to get the data from the online xml file e.g. http://data.one.gov.hk/others/td/speedmap.xml.
It works when I call the javascript from HTML locally (without servlet).
However, it does not work when I call it through jsp and java servlet.
Is there another method such that I can get the data from the online xml file?

contentXML.jsp:

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <p>CONTENT_XML</p>

        <%@ include file="source_file/js_workable.js" %>
        <%@ include file="source_file/data_retrieve.js" %>

    </body>
</html>

data_retrieve.js

<script  LANGUAGE="JavaScript">


         if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
           xmlhttp=new XMLHttpRequest();
         }
         else { // code for IE6, IE5
           xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
         }

         document.write(xmlhttp.status);
         document.write(xmlhttp.readyState);
         document.write(xmlhttp.statusText);

         xmlhttp.open("GET","http://data.one.gov.hk/others/td/speedmap.xml",false);
         xmlhttp.send(); 


         xmlDoc=xmlhttp.responseXML; 

         document.write("<table border='1'>");
         var x=xmlDoc.getElementsByTagName("jtis_speedmap");
         for (i=0;i<x.length;i++){ 
           document.write("<tr><td>");
           document.write(x[i].getElementsByTagName("LINK_ID")[0].childNodes[0].nodeValue);
           document.write("</td><td>");
           document.write(x[i].getElementsByTagName("ROAD_TYPE")[0].childNodes[0].nodeValue);
           document.write("</td></tr>");
         }
         document.write("</table>");

</script>

html file:

<html>
 <body>

<script>
 if (window.XMLHttpRequest)
   {// code for IE7+, Firefox, Chrome, Opera, Safari
   xmlhttp=new XMLHttpRequest();
   }
 else
   {// code for IE6, IE5
   xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
   }
 xmlhttp.open("GET","http://data.one.gov.hk/others/td/speedmap.xml",false);
 xmlhttp.send();
 xmlDoc=xmlhttp.responseXML; 

document.write("<table border='1'>");
 var x=xmlDoc.getElementsByTagName("jtis_speedmap");
 for (i=0;i<x.length;i++)
   { 
  document.write("<tr><td>");
   document.write(x[i].getElementsByTagName("LINK_ID")[0].childNodes[0].nodeValue);
   document.write("</td><td>");
   document.write(x[i].getElementsByTagName("ROAD_TYPE")[0].childNodes[0].nodeValue);
   document.write("</td></tr>");
   }
 document.write("</table>");
 </script>

</body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T05:49:44+00:00Added an answer on June 17, 2026 at 5:49 am

    it is cross domain ajax request, so it was blocked by Access-Control-Allow-Origin rules.

    solution you may use jsp / servlet made a HTTP request to retrive the XML content first, and then your ajax request locally to go on your javascript.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to get data from 2 sources online and would like to show
I would like to get data using SNMP from a router. The data shall
I would like to know how to get data from preference activity when my
I have an SQL statement where I would like to get data of 1200
I would like to get POST data sent to page controller in init() function
Given some arbitrary SQL I would like to get the data types of the
I would like to use the data you get when calling the following URL
As the title suggests I would like to be able to use data from
I am pulling some data from mysql database using PHP, now I would like
I would like to get numbers of comments for each posts using mysql. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.