2010-12-15 34 views
0

所以我想要做的是,通過使用服務進行ip-lookup和geo-lookup,在遊客位置的地圖上放置一個標記.. 目前。雛鳥JQuery/JSON調用時獲取GET錯誤:更新

這是後來被用作腳本,被放置在頁面上,以供應數據庫與他們訪問我們的網站的用戶位置。 然後通過從db中讀取,在用戶所在的地圖上放置點。一種儀表板。

總之..

// 


[ 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); 

    }); 

}); 

}); 

當我試圖運行此,我想我已經到我得到一個GET錯誤什麼的結論,當腳本試圖運行第二個JSON函數。它只是簡單地跳過它。

任何想法可能導致這種情況?

EDIT

我已經改變了可變用於第二JSON-請求。它的工作原理。但是當我在本地機器上試用它時。使用Safari。

試用過Chrome和Firefox。本地和服務器上。只是不會工作。

紅色螢火蟲標註文字:

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>'); 
      }); 

     }); 
    }); 
}); 
+0

Firebug的「網絡」選項卡或Chrome的資源跟蹤器對你得到的錯誤有什麼看法? – 2010-12-15 12:47:29

+0

正如Pekka所問,在網絡檢查員中究竟記錄了什麼?它是GET請求還是OPTIONS請求? – 2010-12-21 10:39:23

回答

0

嘗試改變第二函數的JSON參數。我認爲在爲這兩個函數使用相同的參數名稱時會遇到麻煩。