I'm using a Symfony2 Controller to return a JSON string:
return new Response(json_encode(array('errors' => $errors)));
Basically, I want to return errors to the form. But when I call the action, the JSON output is displayed in my browser. But I want to call the JSON in a callback function in JavaScript (jQuery).
I tried to set the Content-Type to application/json, but it doesn't work in IE because IE wants to save the file.
My JavaScript:
$("#form").submit(function() {
var url = $(this).attr("action");
$.ajax({
type: "POST",
url: url,
data: $(this).serialize(),
success: function(data, textStatus, jqXHR) {
// Ouptut errors
}
});
});
What can I do?