2
有誰知道一個好的級聯/鏈接選擇jQuery的1.4.x插件(S)(或jQuery的UI部件),使用Ajax調用PHP,返回JSON格式的數據填充選項?jquery,ajax,php,json - jquery有沒有很好的級聯/鏈接選擇插件?
有誰知道一個好的級聯/鏈接選擇jQuery的1.4.x插件(S)(或jQuery的UI部件),使用Ajax調用PHP,返回JSON格式的數據填充選項?jquery,ajax,php,json - jquery有沒有很好的級聯/鏈接選擇插件?
這個問題很模糊,但是您可以使用.post()函數將請求發佈到PHP文件,然後讓PHP創建數組並使用json_encode()
將數組編碼爲JSON,然後回顯該JSON數據,可以通過jQuery .post()接收。做這樣的事情:
的jQuery:
$.post("you_php_file.php",{ request: "YOUR_REQUEST" },function(data){
//do something with the data, stored with the variable data
$('ul li:nth-child(1)').html(data[0]);
$('ul li:nth-child(2)').html(data[1]);
},"json")
PHP:
$request = $_POST['request'];
//create an array with the data you want to send to JavaScript
$array = array();
$array[] = 'Hello';
$array[] = 'World!';
echo json_encode($array);
我用這一個(http://remysharp.com/wp-content/uploads/2007/09/select -chain.php)在一個應用程序,但我從來沒有滿意它使用的eval函數,它是非常舊的腳本(jQuery 1.2.x)和...,我從來不喜歡它,但因爲我從來沒有一個時間/知識寫我自己的...我不需要代碼如何做到這一點(謝謝雅各布),但你知道是否有一個真正的,非常酷的(閱讀:好)插件/小部件,有人已經做了? – mojeime 2010-11-07 20:18:59