I got a problem where errors are not being displayed.
Here is my code
$.ajax({
url: '{{ url("userposteditajax") }}',
dataType: 'json',
type: 'post',
data: {firstname:firstname,lastname:lastname,phone:phone,email:email,address:address,country:country,city:city,password:password,role:role,status:status,id:id},
success: function( data, textStatus, jQxhr ){
if(data.message == 'Success')
{
$('#ajax_submit').prop('disabled', false);
location.reload();
$.magnificPopup.close();
}
else {
var errors = data.message;
$('#ajax_submit').prop('disabled', false);
$.each( errors, function( key, value ) {
// console.log(errors);
$('#ajax_error').fadeIn('slow',function(){
$('#ajax_error_mess').html(value);
});
});
}
},
error: function( jqXhr, textStatus, errorThrown ){
$('#ajax_submit').prop('disabled', false);
var errors = jqXhr.responseJSON;
$.each( errors, function( key, value ) {
$('#ajax_error').fadeIn('slow',function(){
$('#ajax_error_mess').html(value);
});
});
}
});
return false;
});
My controller code:
$rules = ['firstname' => 'required|max:20',
'lastname' => 'required|max:10',
'phone' => 'required|max:15',
'email' => 'required|email',
'address' => 'required',
'country' => 'required',
'city' => 'required',
'role' => 'required',
'status' => 'required'];
$validator = Validator::make(Input::all(),$rules);
if( $validator->fails() )
{
$error='';
$mess = $validator->getMessageBag()->toArray();
foreach($mess as $row => $val)
{
foreach($val as $key )
{
$error .=$key." <br />";
}
}
//return json_encode(array('message'=>$error));
return Response::json(array('message'=>$error));
}
The error is not displayed even in console.
The output in response I get is
{"message":"The firstname field is required. <br \/>The lastname field is required. <br \/>The email field is required. <br \/>The address field is required. <br \/>"}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire