jeudi 6 décembre 2018

Laravel - Ajax when Search it Duplicates data

hello when i search in the textbox the data duplicates itself why?

here is my ajax code please check this code as it is the problem why it is duplicating also please make sure that the syntax of it is correct

$('#search').on('keyup',function(){
    $value=$(this).val();
    $.ajax({
        type : 'get',
        url  : '',
        data : {'search':$value},
        success:function(data){
            $('tbody').html(data);
        }
    });
})

my controller

please check this code it might have some issue, i might have some huge data fields, also the buttons which are the update and remove are still not included here

    public function search(Request $request){
    if($request->ajax())
    {
        $output="";
        $employees = DB::table('employeefms')->where('last_name','LIKE','%'.$request->search.'%')
                                             ->orWhere('first_name','LIKE','%'.$request->search.'%')->get();


        if($employees)
        {
            foreach($employees as $key => $employee){
                if($employee->gender==0)
                {
                    $gender="Male";
                }
                else
                {
                    $gender="Female";
                }
            $output.='<tr>'.
                     '<td>'.$employee->employee_no.'</td>'.
                    '<td>'.$employee->last_name.'</td>'.
                    '<td>'.$employee->first_name.'</td>'.
                    '<td>'.$employee->middle_name.'</td>'.
                    '<td>'.$employee->nick_name.'</td>'.
                    '<td>'.$gender.'</td>'.
                    '<td>'.$employee->birthdate.'</td>'.
                    '<td>'.$employee->age.'</td>'.
                    '<td>'.$employee->birthplace.'</td>'.
                    '<td>'.$employee->province.'</td>'.
                    '<td>'.$employee->doMarriage.'</td>'.
                    '<td>'.$employee->height.'</td>'.
                    '<td>'.$employee->weight.'</td>'.
                    '<td>'.$employee->bloodtype.'</td>'.
                    '<td>'.$employee->nationality.'</td>'.
                    '<td>'.$employee->religion.'</td>'.
                    '<td>'.$employee->civil_stats.'</td>'.
                    '<td>'.$employee->sss_no.'</td>'.
                    '<td>'.$employee->tin_id.'</td>'.
                    '<td>'.$employee->phil_no.'</td>'.
                    '<td>'.$employee->pagibig_no.'</td>'.
                    '<td>'.$employee->address_no.'</td>'.
                    '<td>'.$employee->street_no.'</td>'.
                    '<td>'.$employee->brgy.'</td>'.
                    '<td>'.$employee->municipality.'</td>'.
                    '<td>'.$employee->cur_province.'</td>'.
                    '<td>'.$employee->region.'</td>'.
                    '<td>'.$employee->zipcode.'</td>'.
                    '<td>'.$employee->per_address_no.'</td>'.
                    '<td>'.$employee->per_street_no.'</td>'.
                    '<td>'.$employee->per_brgy.'</td>'.
                    '<td>'.$employee->per_municipality.'</td>'.
                    '<td>'.$employee->per_province.'</td>'.
                    '<td>'.$employee->per_region.'</td>'.
                    '<td>'.$employee->per_zipcode.'</td>'.
                    '<td>'.$employee->mobile_no.'</td>'.
                    '<td>'.$employee->tel_no.'</td>'.
                    '<td>'.$employee->email_ad.'</td>'.
                    '<td>'.$employee->guard_name.'</td>'.
                    '<td>'.$employee->guard_add.'</td>'.
                    '<td>'.$employee->guard_relat.'</td>'.
                    '<td>'.$employee->grd_mobile_no.'</td>'.
                    '<a href="/admin/employeemaintenance/'.$employee->id.'/edit" class="btn btn-primary btn-sm"><i class="fa fa-edit"></i>'.
                    '</tr>';
            }
            return Response($output);
        }
    }
}

my search textbox

<input type="text" name="search" id="search" class="form-control">



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

Aucun commentaire:

Enregistrer un commentaire