开发者

Passing values from javascript function to controller?

i m suffering with Passing values from javascript function to controller in cakephp and get using $_POST.

i have tried it by different ways but didn't get success please suggest.

my code is controller

function index(){ 
  $wow开发者_如何学Python='rajesh'; 
  $this->set('data',$wow); 
  $raj=$_POST['value']; 
  echo $raj; 
} 

javascript function

checkLength(obj){ 
  alert(obj); 
  //var raj=document.getElementById("searchText").value; 
  //alert(raj); 
  remoteCall("/cakephp/notes/index","&raj="+obj,""); 
  //window.location.href = "http://localhost/cakephp/notes/index/value=" + obj ; 
}


my guess would be that you want to change this line

$raj=$_POST['value']; 

to

$raj=$_POST['raj']; 

as you seem to want the value of the raj parameter


to use $_POST you need to pass the value in an input element of some kind. Create a hidden field inside a form element, then any javascript values you are interested in passing to your controller, populate the hidden input value then submit.

You can even use ajax to submit the form so the whole page doesn't post back

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜