gpt4 book ai didi

jquery - 从 Symfony2 Controller 中的序列化字符串获取数据

转载 作者:行者123 更新时间:2023-12-03 23:05:33 24 4
gpt4 key购买 nike

我正在尝试找出如何从提交表单的序列化字符串中获取数据。

$(document).ready(function() {
$("#formC").on('submit', function(e) {
var url = $(this).attr("action");

e.preventDefault();

$.post(url,{
data: $("#formC").serialize(),
type: 'post'
}).done(function(data) {
alert(data);
});
});

表格:

<form action="{{ path('advd_p_group_ps_rd_ss') }}" method="post" {{ form_enctype(formBase) }} id="formC">
<thead>
<tr>
<th><input type="checkbox" id="selectall"></th>
<th>{{ 'general.date'|trans }}</th>
<th>{{ 'general.order_number'|trans }}</th>
<th>{{ 'general.description'|trans }}</th>
<th>{{ 'general.company_name'|trans }}</th>
<th>{{ 'general.name'|trans }}</th>
<th>{{ 'form.status'|trans }}</th>

</tr>
</thead>
{% for details in details %}
<tbody>
<tr>

<td><div align="center"><input type="checkbox" class="selectedId" name="selectedId" value="{{details.id}}" onclick="javascript:resetSelectAll();" /></div></td>
<td>{{ details.date | date("m/d/Y") }}</td>
<td>{{ details.order_number }}</td>
<td>{{ details.description }}</td>
<td>{{ details.company }}</td>
<td>{{ details.name }}</td>
<td>{{ details.status }}</td>


</tr>
</tbody>
{% endfor %}

</table>

</div>
</div>
{% if info == 1 %}
<div id="information">
<div id="tableContent">

{{ form_widget(form) }}
<input class="input_button" type="submit" value="Procesar" id="procesar" />
</form>

Controller :

public function groupBatchPrizesRequestedAction(Request $request){
if ( $request->getMethod() == 'POST' ) {
$data = $request->get('data');
}

当我执行die($data)时的输出是这样的:

selectedId=23&selectedId=25&requested%5Bstatus%5D=11&requested%5Bcomments%5D=sdsds&requested%5B_token%5D=e40bc826cce8b756ecce002181301e951e588028

我的问题是,如何从中获取所有“selectedId”、requested_status 和评论?有没有办法将它作为数组发送,一个更容易处理的数组......

最佳答案

使用serializeArray函数正确提交您的数据。

$.post(url,{
data: $("#formC").serializeArray(),
type: 'post'
})

关于jquery - 从 Symfony2 Controller 中的序列化字符串获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18277216/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com