javascript - Catching data in controller -



javascript - Catching data in controller -

i have question javascript , cakephp, need send info via post , recive in other side (the controller) , create normal process have. don't know how can grab data. i'm working ajax

class="snippet-code-js lang-js prettyprint-override">function editfun(clicked_id){ var id = clicked_id; $("#content").empty(); $('#content').html("<b>loading response...</b>"); $.ajax({ type: 'post', url: '/posts/edit', data: (id) }) .done(function(data){ console.log(data); $('#content').html(data); }) .fail(function(data){ $('#content').html(data); }); } class="snippet-code-html lang-html prettyprint-override">public function edit($id = null) { if (!$id) { throw new notfoundexception(__('invalid post')); } $post = $this->post->findbyid($id); if (!$post) { throw new notfoundexception(__('invalid post')); } if ($this->request->is(array('post', 'put'))) { $this->post->id = $id; if ($this->post->save($this->request->data)) { $this->session->setflash(__('your post has been updated.')); return $this->redirect(array('action' => 'index')); } $this->session->setflash(__('unable update post.')); } if (!$this->request->data) { $this->request->data = $post; } }

in case should send id in url. method enough, because controller receive $id param url.

so need alter post arguments:

$.ajax({ type: 'post', url: '/posts/edit/' + id })

javascript php ajax cakephp

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -