Create a new Response
object, do a $response->setJsonContent(array("response" => something))
, then return $response
.
For the AJAX (Jquery):
$.ajax(
{
url: '/controller/action',
type: 'POST',
async: false,
dataType: 'json',
data: {...}
}).done(function (data)
{
console.log(data["response"]);
});
In the controller's action, make a IF that checks if the request is a POST (for security).