1

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.

1
  • Show your console.log() data. Commented Aug 13, 2016 at 5:28

3 Answers 3

2

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/

Sign up to request clarification or add additional context in comments.

Comments

1

See if this works any better:

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

Comments

0

Try this:

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

That's Done.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.