Answer the question
In order to leave comments, you need to log in
How to do ajax authorization for FOSUserBundle on Symfony2?
It is necessary to check the entered fields and return a response in an arbitrary format with a specific error
Answer the question
In order to leave comments, you need to log in
$(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;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question