javascript - How to implement ajax post submission in cakephp -
i have surfed net trying implement ajax post submission in cakephp no avail, how can achieve functionality, 1 on twitter , how update post automatically whenever there new record? post code:
public function add($id = null) { if ($this->request->is('post')) { $this->request->data['post']['user_id'] = $this->session->read('auth.user.id'); $this->post->create(); if ($this->post->save($this->request->data)) { $this->session->setflash(__('the post has been saved.')); return $this->redirect(array('action' => 'index')); } else { $this->session->setflash(__('the post not saved. please, try again.')); } } $users = $this->post->user->find('list'); $this->set(compact('users')); }
and here post form:
<?php echo $this->form->create('post'); ?> <fieldset> <legend><?php echo __('add post'); ?></legend> <?php echo $this->form->input('title'); echo $this->form->input('content'); ?> </fieldset> <?php echo $this->form->end(__('submit')); ?>
try ajax post submission.
replace submit button code following:
<?php echo $this->ajax->submit('submit', array( 'class'=>'btn', 'div'=>false, 'label'=>false, 'url' => array( 'controller' =>'your_controller', 'action' =>'your_function' ), 'update' =>'update_section_id', ) ); ?>
Comments
Post a Comment