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

  • Home
  • SEARCH
  • 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 7503415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T21:12:55+00:00 2026-05-29T21:12:55+00:00

I have found the following piece of code which uses XmlHttpRequest to read JSON

  • 0

I have found the following piece of code which uses XmlHttpRequest to read JSON data from another domain. It works without using JSONP. I thought it is not possible (http://en.wikipedia.org/wiki/Same_origin_policy) . Why does it work?

    <script type="text/javascript">
      // Set up the http request object for AJAX calls
      var http = false;
      if(navigator.appName == "Microsoft Internet Explorer") http = new ActiveXObject("Microsoft.XMLHTTP");
      else http = new XMLHttpRequest();

      // Begin by getting partial codelist for all regions in the United Kingdom from the API in JSON format
      http.open("GET", "http://www.nomisweb.co.uk/api/v01/dataset/nm_1_1/geography/2092957697TYPE480.def.sdmx.json", true);
      http.onreadystatechange=function() {
        if(http.readyState == 4 && http.status == 200) {
          // Evaluate the JSON response
          var jsonlist = eval("(" + http.responseText + ")");

          // String to hold the html for area selection buttons
          var mycodelist = '';

          // Loop through each code in the codelist and build up buttons for the user to click
          for(i = 0; i < jsonlist.structure.codelists.codelist[0].code.length; i++)
          {
             // Get the code value
             var code = jsonlist.structure.codelists.codelist[0].code[i].value;

             // Get the description value
             var desc = jsonlist.structure.codelists.codelist[0].code[i].description.value;

             // Construct the html for this area button
             mycodelist += '<input type="button" onclick="getdata(' + code + ',\'' + desc + '\');" value="' + desc + '"><br>';
          }

          // Display the area selections in the "mylist" div
          document.getElementById('mylist').innerHTML = mycodelist;
        }
      }
      http.send(null); // Make the API request

    </script>

It works in Chrome.

http://www2.esd.org.uk/betaesdmapping/1234.HTML

UPDATE

It does not work in FF 3.6 or IE 7.

Maxim

  • 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-05-29T21:12:56+00:00Added an answer on May 29, 2026 at 9:12 pm

    It is possible to circumvent the Same Origin Policy. Have a look at this wiki.

    This is probably Cross-Origin Resource Sharing.

    Basically, the server that hosts the file that is being requested by AJAX has specified that the requesting page is allowed access to that particular resource.
    In Apache this is done with the following line in the config file:

    Access-Control-Allow-Origin: http://www.example.com

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

Sidebar

Related Questions

I used the following piece of code to read data from files as part
I have found myself unable to explain why the following piece of code works.
We have the following piece of code (idea for this code was found on
I have been looking for solutions and found the following piece of code. But
I have found the following expression which is intended to modify the id of
According to what I have found so far, I can use the following code:
Found interesting thing while compile the following piece of code: 1 class A {
I found the following piece of code in apple guidelines: - (void)accelerometer:(UIAccelerometer*)accelerometer didAccelerate:(UIAcceleration*)acceleration {
I have the following piece of code: class Student { public: Student(){} void display()
I found the following piece of JavaScript code (maybe here at Stack Overflow?) for

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.