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.
That's right, cross domain ajax calls are not allowed. Instead create a "script" element on the page with the src set to that URL.
You can also use $.getScript() - http://api.jquery.com/jQuery.getScript/
精彩评论