mercredi 5 décembre 2018

Laravel / AJAX - Search Box and Search Last Name and Display it on Texbox

How can i search for last name and display the value in my textbox?

my problem now is when i type letter D the page hang and stop from loading it will hang.

as of now i have a ajax and jquery code so when i type a the first letter of my last name which is D then the input should have a value how can i do that?

my another question is, do you think my code in controller <input> and output is correct? or is it a invalid syntax? because im using Form Collectives

here is my code.

my Controller

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

        if($employees)
        {
            foreach($employees as $key => $employee){
                $output.='<input>'.$employee->employee_no.'</input>'.
                $output.='<input>'.$employee->last_name.'</input>'.
                $output.='<input>'.$employee->first_name.'</input>';
            }
            return  Response($output);
        }
    }
}

my Searchbox

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

my Form TextBox which i used the format of Form Collectives

 

my Ajax Code

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

my link of ajax

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>



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

Aucun commentaire:

Enregistrer un commentaire