2013-07-31 32 views
0

我在谷歌工作的地方離https://developers.google.com/places/documentation/search

返回錯誤添加API密鑰這個網址

https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-33.8670522,151.1957362&radius=500&types=food&name=harbour&sensor=false&key=

讓我在瀏覽器精緻漂亮的JSON響應後但是無論何時我想用JQuery.Ajax()解析這些響應,都會給我帶來錯誤。

我找不到這個錯誤背後的原因。我該如何解決這些問題?謝謝。

JS:

<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script> 
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=true&libraries=places"></script> 


<script type="text/javascript"> 

    $(document).ready(function() { 
     $("#submit").click(function(event){ 
      var url="https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-33.8670522,151.1957362&radius=500&types=food&name=harbour&sensor=false&key=<myKey>"; 

      $.ajax({ 
       url: url, 
       type:'POST', 
       dataType: 'json', 
       success: function(data) 
       { 
        alert("success"); 

       }, 
       error:function(){ 
        alert("error"); 
       } 
      }); 

     }); 
    }); 

</script> 

HTML:

<button id="submit">press</button> 

回答

0

的鏈接的ressource不是通過AJAX訪問,因爲訪問是通過同源政策限制,不支持JSONP。使用javascript-places-library的nearbySearch在客戶端獲得結果。

+0

謝謝.is有沒有完整的例子?plz –

-1

數據類型: 'JSONP',

這workd對我!