$(document).ready(function(){
$('#_submit').click(function(e){
e.preventDefault();
$.ajax({
type : $('form').attr( 'method' ),
url : '{{ path("fos_user_security_check") }}',
data : $('form').serialize(),
dataType : "json",
success : function(data, status, object) {
if(data.error) $('.error').html(data.message);
},
error: function(data, status, object){
console.log(data.message);
}
});
});
});
и серверная часть:
public function onAuthenticationFailure(Request $request, AuthenticationException $exception) {
$result = array(
'success' => false,
'function' => 'onAuthenticationFailure',
'error' => true,
'message' => $this->translator->trans($exception->getMessage(), array(), 'FOSUserBundle')
);
$response = new Response(json_encode($result));
$response->headers->set('Content-Type', 'application/json');
return $response;
}