开发者

jquery, ajax, php, json - is there a good cascade/chained select plugin for jquery?

开发者 https://www.devze.com 2023-01-23 16:44 出处:网络
Does anyone know for a good cascade/chained select 开发者_JS百科jquery 1.4.x plugin(s) (or jquery ui widget) that uses ajax call to php that returns json format data for populating options?This questi

Does anyone know for a good cascade/chained select 开发者_JS百科jquery 1.4.x plugin(s) (or jquery ui widget) that uses ajax call to php that returns json format data for populating options?


This question is vague, but you can use the .post() function to post requests to a PHP file and then have the PHP create an array and use json_encode() to encode the array into JSON and then echo that JSON data, which can be received by the jQuery .post(). Do something like this:

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);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号