Autocomplete search with ajax in laravel ……….

1. View page code …..

<script src=”http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js”></script&gt;
<script>
$(document).ready(function(){
$(“#add_b”).click(function(){
$(“#add_board”).slideToggle(“slow”);
});
$(‘form#sv’).submit(function() {
var nam = $(‘input[name=name]’).val();

if(nam!=””)
{

$.ajax({
type: “POST”,
data: { name: nam}
}).done(function( msg ) {

$(“#mks”).html(msg);
//$(“.team_sec”).html(msg[‘results’]);
});
}
else
{
$(“#mess”).html(“<span class=’rd’>Please fill name!</span>”);
}
return false;
});
});
</script>

<div class=”ad_board” id=”add_board”>

{{ Form::open([‘url’ => ‘admin/settings’, ‘method’ => ‘post’,’name’ => ‘form’, ‘id’ => ‘sv’ ]) }}

<div class=”input_b”>
{{Form::text(‘name’, null,array(‘placeholder’ => ‘Add Board name’,’class’ => ‘form-control’,’id’ => ‘input-name’))}}
<div id=”mks”>

ajax code display ….

</div>
</div>

<div class=”input_b”>
{{Form::submit(‘Save’, array(‘name’ => ‘save’,’class’ => ‘btn btn-primary save-board’))}}
</div>

{{ Form::close() }}

</div>

2. Controller function code …..

public function boardadd()
{
$my_data = Input::get(‘name’);
$results = DB::select(“SELECT * FROM users WHERE username LIKE ‘%$my_data%'”);
$html=”<table>”;
foreach($results as $result)
{
$html.=”<tr><td>$result->username”;
$html.=”</td></tr>”;
}
$html.=”</table>”;

return $html;
}

Note:- Please replace ` `  to ‘ ‘ before use

Advertisements