2012-01-30 14 views
0

在我的HtML列表框中只顯示了部分數據列表。我用JSON與PHP和MYSQL來填充我的列表框。我使用了「alert(」Data Loaded:「+ data);」以顯示JSON返回的內容並確定所有數據已成功返回,但是當我查看列表框時,只有52個返回的數據顯示爲3000.即列表停在「A Bronx Tale」Json返回從我的PHP MYSQL查詢中顯示我的Html列表框中只有部分數據

當我嘗試另一種方式通過在我的Html中使用PHP初始化頁面,我可以獲得所有3000個標題。所以我的列表框已經設置好了。

這裏是我的代碼...

//初始化頁面

 function init() {   

      $.getJSON('Reset_DVD.php', function(data) { 
       alert("Data Loaded: " + data); 

       $.each(data, function(key, movie) {  
        $.each(movie, function(id, title) { 
        $('<option />').attr('value', id).text(title).appendTo('select#dvdtitle') 
        });  
       }); 

      }); 
     } 

最後我偏的Html ....

<select name="dvdtitle" id= "dvdtitle" size='10' ></option> </select> 

我的PHP代碼....「Reset_DVD .php「

 <?php 
     include("includes/connection.php"); 

     $final= array(); 

     $result_reset =mysql_query("SELECT * FROM dvd ORDER BY title"); 

     while($rowCatagory = mysql_fetch_array($result_reset)) { 

      $final[] = array($rowCatagory['title']); 
     } 


     echo json_encode($final); 

    ?> 
+1

下拉菜單中的3000個項目是一個非常糟糕的設計理念。 – 2012-01-30 22:28:06

回答

0

聽起來像y ou超出了get響應限制。 getJSON作爲GET請求發送和接收。在14 Helpful jQuery Tricks, Notes, and Best Practices

舉個例子

見7號AJAX方法,讓我們回顧的getJSON,這使我們獲取JSON。

$.getJSON('path/to/json', function(results) { 
// callback 
// results contains the returned data object 
}); 

在幕後,這個方法首先調用$不用彷徨。 $ .get然後編譯傳遞的數據,並再次調用「主」(各種)$ .ajax方法。

get: function(url, data, callback, type) { 
// shift arguments if data argument was omited 
if (jQuery.isFunction(data)) { 
    type = type || callback; 
    callback = data; 
    data = null; 
} 

return jQuery.ajax({ 
    type: "GET", 
    url: url, 
    data: data, 
    success: callback, 
    dataType: type 
}); 
} 

使用.post後代替。 http://api.jquery.com/jQuery.post/

相關問題