lakshay lakshay - 9 months ago 55
jQuery Question

How to serialize a form using jquery .serialize() method?

My Form is:

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

My Jquery is:

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

url:"<?php echo Yii::app()->createAbsoluteUrl('jobs/index'); ?>",
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: