lundi 30 janvier 2017

return json data using ajax in laravel not working

I'm trying to receive an id by first sending it through ajax and then return it in json format in laravel. For some reason, it's not working, also console shows I'm getting a "Internal server error" for this url: http://localhost/public/admin/questions/sort

What could be wrong here?

jquery code:

<script>
            $(document).ready(function () {
                //alert(url);
                $('select[name=selector]').change(function() {
                    var quiz_id=$(this).val();
                $.ajax({
                    method: "POST",
                    url: '',
                    data:{id:quiz_id}
                    }).done(function (msg) {
                        console.log(msg['id']);
                    })
                });
            });
        </script>

routes file

Route::post('questions/sort',['uses'=>'QuestionController@sort','as'=>'admin.questions.sort']);
Route::resource('questions', 'QuestionController');

controller file

   public function sort(Request $request) {
        $id=$request['id'];
        return response()->json(['id'=>$id  ],200);
    }



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire