谷歌地理编码与jsonp ajax,给出一个错误 [英] google geocode vai ajax with jsonp, giving an error

查看:192
本文介绍了谷歌地理编码与jsonp ajax,给出一个错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用google geocode与jsonp的ajax,这里是代码

  jQuery(#getaddress) .on(click,function(){
jQuery.ajax({
dataType:'jsonp',
url:'http://maps.googleapis.com/maps/api / geocode / json',
data:{
地址:'rajshahi',
sensor:false
},
成功:函数(结果){
console.log(results);
}
});

});

josn return非常好用,但它给了这个错误

 无效标签
[关于此错误的折扣]

results:[

json?c。 ..6919370(第2行,第3列)

请让我知道需要做些什么来解决这个问题。

解决方案

我不熟悉Google Geocoder API,但它看起来不支持JSONP请求,返回纯JSON并不包装它在一个JavaScript函数。您需要按照文档中的说明使用google.maps.geocoder。

i am trying to use google geocode vai ajax with jsonp, here is the code

    jQuery("#getaddress").on("click", function () {
        jQuery.ajax({
            dataType: 'jsonp',
            url: 'http://maps.googleapis.com/maps/api/geocode/json',
            data: {
                address: 'rajshahi',
                sensor: false
            },
            success:function(results){
            console.log(results);
        }
    });

});

josn return is cominf nicely but it's giving this error

invalid label
    [Break On This Error]   

    "results" : [

    json?c...6919370 (line 2, col 3)

Please let me know what need to do to solve this.

解决方案

I'm not familiar with the Google Geocoder API, but it looks like it does not support JSONP requests, i.e. is returning plain JSON and not wrapping it in a javascript function. You'll need to use the google.maps.geocoder as described in the documentation

这篇关于谷歌地理编码与jsonp ajax,给出一个错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆