1

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

I have it working using:

See it here: http://jsfiddle.net/5pjha/789/

var url = "http://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=true";

$.getJSON(url, function (json) {
    alert(JSON.stringify(json.results));
});

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

https://poloniex.com/public?command=return24hVolume

https://bittrex.com/api/v1/public/getmarkets

https://api.mintpal.com/v1/market/summary/

Are the following urls not correct JSON ?

Thanks

3
  • 2
    in alert you are using json.results which DOES exist in googleapis, but it does NOT exist in other JSONs. Commented Jun 10, 2014 at 7:40
  • jsonlint.com The validator says they are all valid. What is not working specifically? No results? Commented Jun 10, 2014 at 7:42
  • durrrrrrrrrr thanks.... i best remove this stupid question what a idiot, sometimes one overlooks such simple things Commented Jun 10, 2014 at 7:43

3 Answers 3

1

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 https://api.mintpal.com/v1/market/summary/. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://fiddle.jshell.net' is therefore not allowed access.

Sign up to request clarification or add additional context in comments.

2 Comments

See en.wikipedia.org/wiki/Cross-Origin_Resource_Sharing for more details on why it doesn't work and how to use it.
I checked this one (poloniex.com/public?command=return24hVolume) and it has the header access-control-allow-origin: *
0

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.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.