how to return view html into controller to ajax success

  ajax, laravel

I want to return whole html into controller to ajax response. I am using render() but not getting any data into the return method

Below is my ajax:

$.ajax({
                            type: 'GET',
                            url: '{{url('/filter_each_video')}}',
                            data : { resolution : myCheckboxes, fps : myCheckboxesfps },
                            dataType: 'json',
                            success: function (response) {
                                console.log(response);
                               
                            },
                            error: function (data) {
                                console.log(data);
                                // console.log(data);
                            }
                });

Below is my controller from where actually render the view

function filter_each_video(){
        if(request()->ajax()){
            
            $item = Item::whereIn('format', $_GET['resolution'])->get();
            $formats = DB::table('items')->select('format')->distinct()->get();
            $fps = DB::table('items')->select('fps')->distinct()->get();
            $data['item_count'] = $item;
            $data['item'] = $item;
            $data= $this->sellWise($data);
            $data= $this->starWise($data);
            $data= $this->dateWise($data);
            return view('frontend.pages.videos_for_each_filter', compact('data','formats','fps'))->render();
        }
    }

Below is the view file from where I am set value and tha whole html return to controller to ajax response

<?php
        $html ="";
               $html.= '<div class="row video-list">';

               foreach($data['item'] as $video){

                  $html.= '<div class="item video-item сol-12 col-md-6 col-lg-3 text-white mb-4 pull-left">
                        <div class="item-wrapper display-7">
                            <div class="item-img">Video Name</div>
                        </div>
                        </div>';

                }

                $html.= '</div>';

    return $html;

?>

If anyone have idea what exact i am doing wrong to fetch html content to controller then please let me know

I want to return whole html to the ajax response

Source: Laravel

Leave a Reply