$.post("http://localhost/academico/materias/getid",
ui.item.value,
function(data){
console.log(data);
}, "json");
In my controller the $data variable is always null:
// $data is always null. How come?
public function getid($data = null) {
debug($data);
// Como vamos a retornar solamente datos, no necesitamos el layout.
$this->layout = null;
$this->set('data', $data);
$this->render('/Elements/ajaxreturn');
}
How can I get the value POST’d to be bound to something I can use in the Controller code?
You don’t need to define the $data variable as a parameter to the function, that expects it to be present in the URL. POST data is automatically populated in the Request object.
http://book.cakephp.org/2.0/en/controllers/request-response.html#accessing-post-data
“All POST data can be accessed using CakeRequest::$data. Any form data that contains a data prefix, will have that data prefix removed.”