Related to this question --- > > $ this- > request- > getData (); does not recover the data
I do not know why the variable $ option is not shown in the view, but success if it is showing:
<div class="modalHome">
modificar-foto-cuenta</div>
jQuery + AJAX:
$(document).on("click", "#modificar-foto-cuenta", function() {
var opcion = $(this).attr("id").valueOf();
$.ajax({
type: "POST",
url: "/Users/home/",
data: "opcion = " + opcion,
dataType: 'html',
success: function (response) { console.log(response); },
error: function () { alert('error'); }
});
$('.modalHome').show();
});
Driver:
public function home() {
if($this->request->is('post')) {
$data = $this->request->getData();
$opcion = $data['opcion'];
/*$session = $this->getRequest()->getSession();
$session->write('opcion', $opcion);
$opcion = $session->read('opcion');*/
$this->set('opcion', $opcion);
}
else {
$this->set('opcion', 'No pasa');
}
}
Vista:
<div class="modalHome">
<?php echo $opcion; ?>
</div>
I've tried session , but with the same result