JQuery不会得到json? [英] JQuery won't get json?
本文介绍了JQuery不会得到json?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我正在尝试完成从谷歌获取json数据的简单任务,但是这一点jquery代码将无法运行。你能帮我找出原因吗?
So I'm trying to complete the simple task of getting json data from google, but this little bit of jquery code won't run. Will you please help me figure out why?
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(document).ready(function(){
$.getJSON("http://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=false", function(jsondata) {
alert(jsondata.status);
});
});
</script>
最佳解决方案:添加& callback =?到网址的末尾。非常感谢你所有的帮助!
Best solution: add "&callback=?" to the end of the url. Thank you so much for all your help guys!
推荐答案
它被称为同源政策。简而言之:您的代码所在的域是您的javascript可以与之通信的唯一域(默认情况下)
Its called the Same Origin Policy. In short: the domain that your code is on, is the only domain your javascript can communicate with (by default)
您收到如下错误:
XMLHttpRequest cannot load http://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=false. Origin http://fiddle.jshell.net is not allowed by Access-Control-Allow-Origin.
这篇关于JQuery不会得到json?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文