在javascript中从外部源获取json [英] getting json from external source in javascript
问题描述
Json发布了javascript和jquery。
尝试使用javascript加载一些JSON。
Json issues with javascript and jquery. Trying to load some JSON using javascript.
我使用它:
查看这里: 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/
以下网址是否与JSON不正确?
Are the following urls not correct JSON ?
谢谢
推荐答案
google的api设置访问控制 - 允许-Origin 标题为 *
,因此您可以通过跨域访问它。
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无法加载 https://api.mintpal.com/v1/market/summary/ 。
请求的
资源上没有Access-Control-Allow-Origin标头。原因' http://fiddle.jshell.net '因此不允许
访问。
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.
这篇关于在javascript中从外部源获取json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!