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

标签 jquery symfony post serialization

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

$(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/

相关文章:

php - Ajax删除功能不起作用

javascript - 生成并下载网页截图而不丢失样式

javascript - 改进点击菜单点击外部关闭多个菜单的子菜单

php - Symfony2 bundle 和 Travis-CI

php - 如何获取与 symfony 验证错误相关的对象

php - 如何使用 cURL 发送原始 POST 数据? (PHP)

javascript - Yii2 ActiveForm Ajax POST 被调用两次

go - 使用 POSTMAN 访问 FormValue Golang 中的 POST 请求值

javascript - 无法将带有单引号的变量附加到 anchor 标记的标题

php - isClicked() symfony 中的 ':' 和 '?' 是什么意思