如何使用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.

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/

See if this works any better:

var data = $('#main-form').serializeArray();

Try this:

 var data = $("form#main-form").serialize();

That's Done.