Google Maps API - 无法使用Ajax?即使使用json? [英] Google Maps API - Can't use Ajax? Even with json?
问题描述
我试图在某些jQuery ajax中使用google maps API,但是看起来我无法做到这一点,因为它是跨域的,尽管我使用的是json?
这是为什么?我应该怎样解决这个问题?
b url:'http://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=405+Lexington+Avenue+Manhattan+NY',错误:函数(请求,状态){
alert('fail');
},
success:function(data,textStatus,jqXHR){
alert('success');
}
});
谢谢!
返回json内容不会将您排除在跨域限制之外。 (你可能会在这里混淆json和 jsonp 。 )
你可以使用script,就像另一个人指出的那样,但我建议改用javascript api。这可能是设计用于服务器端代码。
I was trying to use the google maps API within some jQuery ajax, however it looks like I can't do this because it's cross-domain, even though I'm using json?
Why is this? What should I do to resolve this?
$.ajax({
type: "GET",
url: 'http://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=405+Lexington+Avenue+Manhattan+NY',
error: function(request, status) {
alert('fail');
},
success: function(data, textStatus, jqXHR) {
alert('success');
}
});
Thanks!
Returning json content doesn't exclude you from cross-domain restrictions. (You might be confusing json and jsonp here.)
You can use script, as another person noted, but I would recommend switching to javascript api instead. This one is probably designed to be used in server-side code.
这篇关于Google Maps API - 无法使用Ajax?即使使用json?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!