jeudi 27 octobre 2016

POST 500 (Internal Server Error) Ajax

I want to send post request with ajax to controller in laravel. The ajax request send two input arguments and I want controller to find the column in the database with the first argument and then to set the name attribute with the second input argument. But I have this error message in console 500 (Internal Server Error).

Ajax function:

var $emailInput = $('input[name=eemail]').val();
var $finduser = $('[name=userName]').val();

$.ajax({
       type:"POST",
       url:'/code/task1/public/editUserAdmin',

       data: {
          'emailInput' : $emailInput,
           'finduser' : $finduser,
           },
          success:function(data){

       //  $("#editEmail").attr("readonly", true);
       //  $("#editEmail").val(data[0].name);

           alert("OK");
           }

   });

Route:

Route::post('/editUserAdmin', 'usersController@editUserAdmin');

Controller function:

$findUserInput = $request->input('finduser');
        $user = User::where('name',$findUserInput)->first();


         if(!$user){
            return response()->json(['status'=>false,'Description' => 'User could not be found.']);
        }
            //$user->name = $request->input('nameInput');
            $user->email = $request->input('emailInput');

            $user->save();
}

And also i import csrf everywhere because last time when I was making AJAX call i have problem with this csrf and the following code has fixed my problem, but now is not working.

<meta name="csrf-token" content="">

 $.ajaxSetup({
                headers:{
                    'X-CSRF-TOKEN' : $('meta[name="csft-token"]').attr('content')
                }
            });  

        $.ajaxSetup({
                   headers: {
                    'X-CSRF-TOKEN': $('[name="_token"]').val()
                }
            });

and this 
<h3 class="media-heading" name="userName"></h3>
<input type="hidden" name="_token" value="">
<input type="text" class="form-control paddingzero" class=text-center" readonly value="Name Name">
<input type="text" class="form-control paddingzero" class=text-center" name="eemail" id="editEmail" readonly value="">

Any idea?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2eTFdvf
via IFTTT

Aucun commentaire:

Enregistrer un commentaire