i want to show toaster on success or failer so i tried this code
$.ajax({
type: "GET",
dataType: "json",
url: '{{ route('users.update.visit_clear') }}',
data: {'visit_clear': visit_clear, 'user_id': userId , 'location': location , 'cs_location': cslocation },
success: function (data) {
if (data.message != ""){
toastr.success(data.message);
}
}
error: function (data) {
toastr.error(data.message1);
}
});
and in controller i have condition
if($var <= 1){
return response()->json(['message' => 'User status updated successfully.' ]);
}
else{
return response()->json(['message1' => 'Visit Failed Distance is too long' ]);
}
if i use error:function it doesnot response me
To be in the
errorajax callback you have to return an http error code (ex: 500, 400 etc).You can check the different http error codes here https://en.wikipedia.org/wiki/List_of_HTTP_status_codes.
You can add a
status codeas a second argument in yourelseresponseex:
return response()->json(['message1' => 'Visit Failed Distance is too long' ],500);