mardi 12 septembre 2017

returning a view from controller after getting data from ajax in laravel

I am sending data-id through Ajax to controller. I am even able to retrieve data from database with using that data-id but unable to return a view in that controller function. print_r shows the data in controller if a comment the return part otherwise I get this error "500 (Internal Server Error)"

Ajax call:

$(document).ready(function(){
                //
                    $(document).on('click','#edit',function(){
                    var dataId = $(this).data("id");

                    $.ajax({

                        type:'get',
                        url:"{!! URL::to('edit') !!}",
                        data:{'id':dataId,},


                        success:function(data){
                            console.log('success');
                            console.log(data);
                        },
                        error:function(){

                        },
                    });
                });

Routes:

Route::get('/edit','CandidateController@update');

Controller:

 public function update(Request $request){
        $id  = $request->id;
        echo"$id";
        $candidate = new Candidate;
        $cand = $candidate->where('id', '=', $id)->first();
        print_r($cand);

        return view('add')->with('cand', $cand);

    }



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire