lakshay lakshay - 1 year ago 110
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.

Answer Source

From .serialize(); :

the element must have a name attribute.

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

Here's a demo:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download