Skip to content Skip to sidebar Skip to footer

Calling Json File From External Sources

I used this JavaScript to call my JSON data from an external source. The json data will load from server. So, what will be the script that I can get the markers from google map usi

Solution 1:

I get two javascript errors in your code snippet:

  1. XMLHttpRequest cannot load http://www.tripleclickstudio.com/json/file.json?tags=location&tagmode=any&format=json. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.

  2. Uncaught TypeError: Cannot read property 'length' of undefined on this line:

for(var i = 0; i < responses.length; i++) {  

Because responses doesn't exist when you are running the loop. $.getJSON is asynchronous, the data isn't populated until the callback function is run (which you haven't defined). Your first problem, however, is that there is a security policy preventing you from downloading it with $.getJSON. You either need to get permission to download it for your domain (the appropriate Access-Control-Allow-Origin in the header) or to download it via JSONP.

However, when I do that, I get a syntax error in your JSON.

Post a Comment for "Calling Json File From External Sources"