I have an ajax in my view add that does an asynchronous request in an action test in my controller, in this function I need to return the $ balance variable for my view add, I would like to know how I can send this data and how they arrive in my view.
Below is my ajax function:
$('#entity').click(function(){
var campanha = $('#entity').serialize()
console.log(campanha);
$.ajax({
type: 'post',
data: campanha,
url:'<?php echo Router::url('/emailMarketings/test/'); ?>',
})
});
And here's my action:
public function test() {
if ($this->request->is('post')) {
$teste = $this->request->data;
}
// debug($teste); die;
// $this->redirect($this->referer());
$balance = $this->Balance->find('first', array('order' => array('Balance.cota_email=' => $teste['Balance']['campaigns'])));
}
This is my role, I would like to send this variable to my view and print it there. But I do not know how to send her to my view.