jquery的表单内容序列化方法serialize
jquery的表单内容序列化方法serialize
一、前端
<form class="search_from">
...
</form>
var container = $('#xx_div');
var search_form = $(container.find('form.search_form'));
var param = search_form.serialize();
$.post(url,param,function(r){},'json');
批注:
console.log(search_form);
console.log(search_form.serialize());
[form.search_form]index....ortscan (line 164)
ip=&port=&service=&o_ip_type=&status=&hostname=&department_id=&domain=&deal=-1&start_time=&end_time=&index=1&size=16
serialize()是jquery的一个方法,序列表表格内容为字符串
还有Array<Object>serializeArray() 返回 JSON 数据结构数据。
二、后端
$str = Yii::app()->request->getParam('param');
parse_str($str, $param);
批注:parse_str() 函数把查询字符串解析到变量中。
parse_str("id=23&name=John%20Adams",$myArray);
print_r($myArray);
输出:
Array
(
[id] => 23
[name] => John Adams
)