Hi guys, I have tried using what you did here but for some reason it doesn't work for me, on the javascript is not showing me any response back, could be that my javascript is wrong? i see that it apparently calls the Action but it doesn't come back with data unless I leave the view undisabled in which case it won't bring the data I have sent but only the general layout I already have.
This is my JS:
<script type="text/javascript">
$(document).ready(function() {
$('#fieldDept').change(function() {
//alert("ingreso paso 2");
$.ajax({
url: "formulario/listUsers",
success: function(result){
$("#udiv").html(result);
}});
});
});</script>
And my Action I have tried both of this with no succes:
public function listUsersAction()
{
$this->view->disable();
$request =$this->request;
if ($request->isPost()==true) {
if ($request->isAjax() == true) {
header('Content-type:application/json;charset=utf-8');
echo json_encode([1, 2, 3]);
}
}
}
And the other one:
public function listUsersAction()
{
$this->view->disable();
$request =$this->request;
if ($request->isPost()==true) {
if ($request->isAjax() == true) {
// Getting a response instance
$response = new Response();
$feed = "<h1>respuesta</h1>";
$content = json_encode($feed);
$status = 202;
$description = "OK";
$contentType = "application/json";
// Set the content of the response
$response->setStatusCode($status, $description);
$response->setContentType($contentType, 'UTF-8');
$response->setContent($content);
return $response;
}
}
}
What am i doing wrong?
Thanks in advance