2015-07-28 69 views
0

我試圖從instragram API獲取json響應沒有結果。語法錯誤:缺失;之前的聲明[JSONP,Instagram的API]

我使用低於該獲取數據的代碼,但與錯誤Uncaught SyntaxError: Unexpected token :

<script type="text/javascript"> 
    $(document).ready(function(){ 
     $.ajax({ 
      type : "Get", 
      url :"https://api.instagram.com/v1/media/search?access_token=MYTOKEN&lat=00.0&lng=00.0&distance=30000?callback=?", 
      dataType :"jsonp", 
      jsonp: false, 
      jsonpCallback: " ", 
      success : function(instagramres){ 
       alert(instagramres); 
       document.write(instagramres.meta.code); 
      }, 
      error : function(httpReq,status,exception){ 
       alert(status+" "+exception); 
      } 
     }); 
    }); 
</script> 

我已經改變jsonp:falsejsonp:true沒有結果。

通過Chrome瀏覽器開發控制檯我的截圖: Chrome Dev Console output

+0

錯誤在什麼時候被拋出? –

+0

刪除'jsonp:false','jsonpCallback:'「'並將'Get'改爲'get'。您最好使用json的簡寫形式 - > [http://api.jquery.com/jquery.getjson/](http://api.jquery.com/jquery.getjson/) – lshettyl

+0

at'jsonpCallback: 「testcallback」,'我得到'parsererror:錯誤testcallback未被調用。 如果我刪除此行我得到'parsererror錯誤:jQuery181011872481792222633_1438084410647沒有called' –

回答

1

正如我所說的在我的評論,你不需要PARAMS如type(因爲默認情況下它是get)和jsonpCallback(除非你想擁有自己的回調方法)。您可以通過jsonp param指定回調。看看下面的代碼,看看它是否適合你。

$(document).ready(function(){ 
    $.ajax({ 
     url: "https://api.instagram.com/v1/media/search?access_token=MYTOKEN&lat=00.0&lng=00.0&distance=30000", 
     // The name of the callback parameter 
     jsonp: "callback", 
     // Tell jQuery we're expecting JSONP 
     dataType: "jsonp", 
     // Deal with the response 
     success: function(instagramres){ 
      alert(instagramres); 
     } 
    }); 
}); 
+0

你是對的! '輸入:「get」'和'jsonp:「false」'創建問題。現在我解決它。 Thanks @lshettyl –

相關問題