Reputation: 712
I'm performing a ajax call with jsonp to the google map api v3, but it always goes into the error function, and in the firefox console log I get the error
SyntaxError: invalid label "results" : [
By clicking it I can see that I get all the right information in the browser, but for some reasons I receive this syntax Error message.
Ajax call:
$.ajax({
url: "https://maps.googleapis.com/maps/api/geocode/json",
data: { latlng: latitude +","+longitude, sensor: "true" },
dataType: "jsonp",
success: function (json) {
alert(json.d);
},
error: function () {
alert("Hit error fn!");
}
});
Any clue?
Upvotes: 1
Views: 1133
Reputation: 382274
Replace
dataType: "jsonp",
with
dataType: "json",
because you're doing a json request, not a jsonp one.
And you're not supposed to get something in json.d
. You'd better alert (or console.log) json
or json.results
.
Note that you may not use Google's geocoding API from outside of a page including a map (your origin wouldn't be accepted).
Upvotes: 1