laravel validation return status 302

Viewed 5150

I have a form and I can send data through and get data in controller and see it but when use validation as below:

$validation= $request->validate([
  'title' => 'required|unique:posts|max:255',
   'body' => 'required',
   'message' => 'required'
  ]);

I have status 302 I don't know what to do

2 Answers

Http Status Code 302 means that the API (server) requests a redirect. That is the expected behavior of Laravel validation if the validation do not pass. If you want Laravel to return json instead, add the following key value pair to your request headers.

accept: application/json

Insert Accept: application/json in ajax header

                $.ajax({
                url:'{{route('fetchMunCit')}}' +'/'+id,
                type:'GET',
                dataType:'json',
                Accept: application/json
                    success:function(response)
Related