cakephp - How do I use RequestHandler to accept data from ajax? -


i try send data form ajax cakephp cotroller

function loadtooltip(obj, $user_id) {  //ajax  var req = inint_ajax();  req.onreadystatechange = function () {        if (req.readystate==4) {            if (req.status==200) {                 displaytooltip(obj, req.responsetext);            }        }   };   req.open("post", "http://127.0.0.1/cakeplate/tooltips/tooltip/", true);   req.setrequestheader("content-type", "application/x-www-form-urlencoded");  req.send($user_id);  

};

this controller

<?php class tooltipscontroller extends appcontroller{ var $name = 'tooltips'; var $uses = array('reply','user'); var $component = array('requesthandler','javascript','ajax'); var $layout =  'tooltip';   function tooltip($user_id=null){                  if(!empty($user_id)){                     $tooltip = $this->reply->user->findbyid($user_id);                     $this->set('tooltip',$tooltip);                 }  } }  ?> 

i need me modified code

the way you're doing @ moment in controller, won't me able user_id, because var passed through method of http.

this variable accessible if make request example url: http://example.com/cakeplate/tooltips/tooltip/1 1 $user_id.

if send request post, can access values in var $this->data way able process request based in var pass controller.

another problem face controller need render view, suggest take @ http://book.cakephp.org/view/1238/rest, there can see how can create route make controller parse view, different custom layout, json (the 1 suggest in case), , can show in view json value.

last, important well, suggest use jquery javascript part, think easier, can check @ http://api.jquery.com/jquery.get


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

c# - SharpSVN - How to get the previous revision? -

php cli reading files and how to fix it? -