2012-12-11 79 views
3

我有下面的代碼,它應該獲取輸入字段的值,將值發送到imdbapi.org並處理髮回的JSON。 我包含一個元素,顯示輸入字段的值,但有些字符串會切斷字符串。見this test case處理輸入值時發生錯誤,通過JSON發送

$("form > input#movname").keyup(function() { 
    var inputval = encodeURI($("form > input").val()); 
    $.getJSON('http://imdbapi.org/', 
    { 
     title: inputval, 
     plot: "none", 
     limit: "5" 
    }, 
    function(data) { 
     var items = []; 
     $.each(data, function(key, val) { 
      items.push('<li id="'+val.imdb_id+'">'); 
      items.push('<img src="'+encodeURI(val.poster)+'" />'); 
      items.push('<strong class="title">'+val.title+'</strong><br />'); 
      items.push('<div>'+val.rated.replace("_"," ")+'</div>'); 
      items.push('</li>'); 
     }); 
     items.push('<li id="debug">'); 
     items.push('<img src="src/nocover.png" />'); 
     items.push('<strong class="title">'+$("form > input").val()+'</strong><br />'); 
     items.push('</li>'); 
     var html = items.join(''); 
     $("#suggestions").html(""); 
     $('<ol/>', { 
      'class': 'moviessuggestions', 
      html: html 
     }).appendTo('#suggestions'); 
    }); 
}); 

回答

0

貌似limit是不必要的(錯誤的用法?),使用

{ 
    title: inputval, 
    plot: "none" 
} 

,它工作正常。

+0

哇,謝謝,它的作品! – aNewStart847