2016-07-05 8 views
2

いくつかのコードに問題があります。ここでJSONレスポンスは次のようになります。

{"cars":"1","bikes":"1"} 

ここでjQueryのコードは次のとおりです。

$(function() { 
    $.getJSON('https://myurlhere.com?filename=aapl-c.json&callback=?', function(data) { 
     // Create the chart 
     $('#container').highcharts('StockChart', { 
      rangeSelector: { 
       selected: 1 
      }, 
      title: { 
       text: 'AAPL Stock Price' 
      }, 
      series: [{ 
       name: 'AAPL', 
       data: data, 
       tooltip: { 
        valueDecimals: 2 
       } 
      }] 
     }); 
    });  
}); 

ここで私が取得していますエラーです:私は間違っ

SyntaxError: missing ; before statement {"cars":"1","bikes":"1"}

何をやっているが、ここに?

答えて

2

$.getJSONドキュメントから:

If the URL includes the string "callback=?" (or similar, as defined by the server-side API), the request is treated as JSONP instead.

あなたの戻りデータがJSON形式ではなく、JSONPであるので、これはあなたの問題の原因です。リクエストのクエリー文字列からそのプロパティを削除するだけで済みます。

$.getJSON('https://myurlhere.com?filename=aapl-c.json', function (data) { 
    // the rest of your code... 
}); 
関連する問題