getting json from external source in javascript

Json issues with javascript and jquery. Trying to load some JSON using javascript.

I have it working using:

See it here:

var url = ",+Mountain+View,+CA&sensor=true";

$.getJSON(url, function (json) {

But it dosnt work on the following urls, why is this?

Are the following urls not correct JSON ?




The google's api set the Access-Control-Allow-Origin header to *, so you could access it by cross domain.

While other urls you provided do not, so you will got an error like below:

XMLHttpRequest cannot load No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin '' is therefore not allowed access.


I believe the issue is down to whether or not the servers you are requesting your JSON from have cross-origin resource sharing (CORS) enabled.

you can see in the headers from the google service that they set Access-Control-Allow-Origin:* This is not the case for teh other URL's you list.

To get around this you will need some form of proxy so that you can request from a server either on the same domain or a server that enables CORS.


For ajax request to any server, You need to define Access-Control-Allow-Origin header for client. which is absent in given. You need to define origin of XMLHttp request in server who can request.

For more info refer this link


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.