doudou20145 2016-08-13 05:16
浏览 134
已采纳

如何使用jquery .serialize()方法序列化表单?

My Form is:

<form class="something" id="main-form">
 -----content----

My Jquery is:

 $("form :input").change(function() {
var data = $('#main-form').serialize();
console.log(data);


$.ajax({
        url:"<?php echo  Yii::app()->createAbsoluteUrl('jobs/index'); ?>",
        //dataType:"json",
        type: "POST",
        data: $('#main-form').serialize(),
        success: function(data){
        }
    });
});

But the form is not serialized.The data field is coming empty.Please help.

  • 写回答

3条回答 默认 最新

  • dongxiang7276 2016-08-13 05:32
    关注

    From .serialize(); :

    the element must have a name attribute.

    So make sure you give all inputs a name='whatever'.

    Here's a demo: http://jsfiddle.net/CWJDj/1/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?