使用 phps json_encode() 生成响应,并在客户端使用 jquery 读取它?
$.getJSON('youpage.php', function(data) {
$.each(data, function(key, value) {
alert(key + '=>' + value);
});
}
http://php.net/manual/en/function.json-encode.php
更新
in regards to communication the other way, from the client to php. It all depends on the task at hand really. If the data in the drop down purely depend on the entries on the form, and they are otherwise stateless. Then,the best route will depends on your backend code, you could do a ajax post, with the individual variables, or concatenate them into one variable before sending, and then splitting them up on the backend. Or, as you say, you could create a json string and then use json_decode on the backend.
Which route is fit for purpose depends on many factors, and I dont think there is a right or wrong error.
Personally, I would generate a AJAX post request (im not a php coder though) to the backend, and then process the request object directly. You still would need to process a data structure, so why add the overhead/extra-step of deserializing json from the request.