2014-09-28 128 views
1

我接近獲取json數據的解決方案,只是得到錯誤: SyntaxError:missing;語句之前Ajax jsonp丟失;錯誤

我的JSON數據是這樣的:

{ 「CUSTOM1」: 「」, 「出生日期」:空, 「CUSTOM2」: 「」, 「特製3」: 「」, 「custom4」:」 「,」custom5「:」「}

我正在使用jsonp。這解決了我的問題與CORS(跨源請求被阻止) 在調試器中,我可以看到NET中的數據。 我有多接近? 索姆讓我最後一次解決我的問題?

<script type="text/javascript"> 
function getdata() { 
    $.ajax({ 
     type: 'GET', 
     url: 'http://myurl/api/getUser/22?_key=123456789', 
     dataType: 'jsonp', 
     //contentType: "application/jsonp", 
     success: function (data) { 
           $('#badge').append(result); 
     } 
    }); 
} 

回答

0

你有你的Ajax響應類型設置爲jsonp而不是json

dataType: 'jsonp' 

您可以在jquery docs on $.ajax閱讀更多關於它。另外,正如我所看到的,您試圖在成功回調中追加的result變量未聲明爲&初始化在您提供的代碼中的任何位置。

+0

將tejson更改爲與jsonp相同的問題(忘記調整它) – user2385302 2014-09-28 10:29:02