tags:

views:

58

answers:

2

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='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 ; 
}
+1  A: 

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

Prescott
+1  A: 

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

seanizer