2012-01-18 14 views
3

私はsolrとjqueryを使って自動挑戦をしようとしています。予期しないトークン: JSONデータIクロームJqueryを使用してJSONを解析できません

キャッチされないでSyntaxErrorで実行中に

$(関数(){

$("#artist").autocomplete({ 
     source: function(request, response) { 
      $.ajax({ 
       url: 'http://localhost:8983/solr/terms?terms.fl=heading&terms.prefix=' 
       +request.term+'&wt=json&json.nl=map', 

       dataType: "jsonp", 

       data: { 
        q: request.term, 
        rows: 10, 
        omitHeader: true, 
       }, 
       success: function(data) { 
        response($.map(data.terms.heading, function(item) { 
         return { 
          label: item, 
          value: item 
         } 
        } 
        ) 
        ); 
       } 
      }); 
     }, 

     minLength: 2, 
     select: function(event, ui) { 
      log(ui.item ? 
       "Selected: " + ui.item.label : 
       "Nothing selected, input was " + this.value); 
     }, 
     open: function() { 
      $(this).removeClass("ui-corner-all").addClass("ui-corner-top"); 
     }, 
     close: function() { 
      $(this).removeClass("ui-corner-top").addClass("ui-corner-all"); 
     } 

    }); 
}); 

私は、次のエラーを取得しています。このために私は以下のコードを書きました午前取得はこの

{ "用語":{ "見出し":{ "答え":24、 "アンサリ":5}}}である

は、私は次のリンクを相談 http://jqueryui.com/demos/autocomplete/#remote-jsonpしかし、私は解決策を見つけることができません。私が間違っていることを提案してください

+0

あなたは間違っている投稿したコードで

もっと ")};"最後に。またdataType: "jsonp"ではなく "jsonp"でなくてはなりません。 – CBusBus

+0

おそらく$ .map(data.d.terms.heading、function(item) –

+0

を試してみてください) –

答えて

3

Cross OriginリソースにアクセスするためにJSONPを指定しましたが(正確には)、純粋なJSONではなくJSONPを発行するようSolrに伝えていません。

のパラメータにjsonp: 'json.wrf'を追加します。 http://xplus3.net/2010/09/21/solr-and-jsonp/

+0

回答ありがとうございました – sid

+0

jsonp: 'json.wrf'ではなくjson: 'json .wrf "。添付されたリンクは正しいが、引用された回答は間違っている。 –

+0

@BalajiNatarajanありがとう – Alnitak

関連する問題