javascript - Catching data in controller -
I have a question about javascript and cakepap, send me data through post and on the other side (controller) and I already have a normal procedure. But I do not know how I can handle the data I am working with Ajax
< Div class = "snippet-code">
function editFun (clicked_id) {var id = clicked_id; $ ("#type") below () .; $ ('# Content'). Html ("& lt; b & gt; Loading Feedback ... & lt; / b & gt;"); $ Ajax ({type: 'post', url: '/ post / edit', data: (id)}). (Function) {console.log (data); $ ('# content') .html (data);}). File (function (data) {$ ('# content') .html (data);} ); } Edit the public function ($ id = null) {if (! $ Id) {New NotFoundException}
-> Request-> (array ('post', 'put'))) {$ this-> Post- & gt; Id = $ id; If ($ -> this-> Post-> Save ($ - this-> request-> Data)) {$ this- & gt; Session-> Set Flash (__ ('your post has been updated.')); $$ -> (- 'Action' => Index;); Redirect;); } $ This- & gt; Session-> Set Flash (__ ('Unable to update your post.')); } If (! $ This-> Request-> Data) {$ this-> Request-> Data = $ post; }}
in that state You must send your ID in the URL. So even the GET method is also sufficient because you get the $ id
ultimate from the Controller URL.
So all you need to change is logic:
$ Ajax ({type: 'post', url: '/ post / edit /' + id})
Comments
Post a Comment