dimanche 6 mai 2018

LIVE SEARCH IN LARAVEL WITH AJAX

Hello team I failed to display data after type to the search button there is no error that displayed Here is my controller

  public function search(Request $request)

{
    if ($request->ajax()) {
        $output = "";

        $products = DB::table('particulars')->where('item_name', 'LIKE', '%' . $request->search . "%")->get();

        if ($products) {
            foreach ($products as $key => $product) {

                $output .= '<tr>' .

                    '<td>' . $product->id . '</td>' .
                    '<td>' . $product->item_name . '</td>' .
                    '<td>' . $product->quantity . '</td>' .
                    '<td>' . $product->price . '</td>' .
                    '</tr>';

            }
            return Response($output);
        }
    }
}

my view

<td>
        <div class="row">
            <div class="col-lg-12" style="">
                <div class="input-group">
                    <div class="input-group-addon">
                        <span class="glyphicon glyphicon-search"></span>
                    </div>
                    <input type="text" class="form-control" id="search" name="search" placeholder="Search here...">
                </div>
            </div>
        </div>
    </td>

Here is the script

   <script type="text/javascript">
    $('#search').on('keyup',function(){
        $value=$(this).val();
        $.ajax({
            type : 'get',
            url : '/search',
            data:{'search':$value},

            success:function(data){

                $('tbody').html(data);

            }
        });
    })
</script>

but I failed to retrieve data and show no error please team help me



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire