0

This the code I am using to submit form via ajax.

<?$data = $this->Js->get('#form_emp')->serializeForm(
                                            array(
                                            'isForm' => true,
                                            'inline' => true)
                                        );?>
<?php echo $this->Js->submit('submit.png',
array(
    'url' =>'/employees/update_details',
    'update' => '#update_here', 
                'data'=>$data,
                'async' => false,
               'dataExpression'=>true,
                'method' => 'POST'


                ));
 echo $this->Form->end();

When I am doing a debug on the action post data is displayed as empty. How to fix it?

1 Answer 1

1
<?php echo $this->Form->submit('submit', array('onclick'=>'post_data(); return false;')) ?>
  • return false is declared there so the button don't fire and submit/refresh the page

And then in your javascript file (or in the view if you like)

function post_data(){
   var formData = $('#form_emp').serialize();
   $.ajax({
       url: '/employees/update_details/',
       type: 'post',
       data: formData,
       success: function(response){
           alert('success');
       }
}
Sign up to request clarification or add additional context in comments.

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.