1

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

1 Answers1

0

To be in the error ajax 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 code as a second argument in your else response
ex: return response()->json(['message1' => 'Visit Failed Distance is too long' ],500);

ml59
  • 1,495
  • 1
  • 9
  • 10