【问题标题】:Getting an GET-error when nestling JQuery/json-calls: Update嵌套 JQuery/json 调用时出现 GET 错误:更新
【发布时间】:2010-12-15 12:44:26
【问题描述】:

所以我现在要做的是,通过使用 ip-lookup 和 geo-lookup 服务,在地图上的访客位置放置一个标记。

稍后将用作脚本,放置在页面上,为数据库提供用户访问我们网站的位置。 然后通过从数据库中读取,在用户所在的地图上实时放置点。一种仪表板。

无论如何..

//


[ Above this i've declared a googlemap, hence the google.maps-references ]

$('#addButton').click(function(){



    var ipurl = 'http://jsonip.appspot.com/';

  //displays the users ip-adress in json-format


     $.getJSON(ipurl,function(json){

      var ip = json.ip;

//gets the ip from the above url

      var geourl='http://freegeoip.appspot.com/json/' + ip;

//gets location details from the ip in json-format


      $.getJSON(geourl,function(json){

       var myLatlng = new google.maps.LatLng(json.latitude, json.longitude);
        //set the position for the map


       var marker = new google.maps.Marker({
        position: myLatlng,
        title:"Hello World!"
       });

       marker.setMap(map);

  });

 });

});

当我尝试运行它时,我想我已经得出结论,当脚本尝试运行第二个 JSON 函数时,我得到了一个 GET 错误或其他东西。它只是跳过它。

知道是什么原因造成的吗?

编辑

我已更改第二个 JSON 请求的变量。它有效。但就在我在本地机器上尝试时。使用 Safari。

在 Chrome 和 Firefox 中尝试过。本地和服务器上。就是行不通。

FireBug 中的红色标记文本:

GET http://example.com/json/ 200 OK 168ms

$(document).ready(function(){

    $('#addButton').click(function(){

        var ipurl = 'http://jsonip.appspot.com/';

        $.getJSON(ipurl,function(json){

            var ip = json.ip;

            var url='http://freegeoip.appspot.com/json/' + ip;

            $('#result').append(
                '<p>1: ' + ip + '</p>' + 
                '<p>2: ' + url + '</p>');

            $.getJSON(url,function(json2){

                $('#result').append('<p>' + json2.longitude + ' / ' + json2.latitude + '</p>');
            });

        });
    });
});

【问题讨论】:

  • Firebug 的“net”选项卡或 Chrome 的资源跟踪器对您遇到的具体错误有何说明?
  • 正如 Pekka 所问的,网络检查器中究竟记录了什么?是 GET 请求还是 OPTIONS 请求?

标签: javascript jquery json geolocation getjson


【解决方案1】:

尝试更改第二个函数的 json 参数。我认为在对两个函数使用相同的参数名称时会遇到麻烦。

【讨论】:

    猜你喜欢
    • 2020-08-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-23
    • 1970-01-01
    • 1970-01-01
    • 2015-04-21
    相关资源
    最近更新 更多