0
Eae guys td well? so I’m trying to develop an application in Laravel and I happen to be putting an Autocomplete but it’s not running. Please help me out there!
This here is the ajax
$(document).ready(function(){
$('#users').keyup(function () {
var q=$(this).val();
if(word.length>3) {
$.ajax
({
type: "GET",
url: "/User/Dados",
data: {q:q},
contentType: "json",
cache: false,
success: function(data, status, xhr)
{
$('#users').val(data[0].value);
}
});
}
});
This one is html
<i class="material-icons prefix">textsms</i>
<input type="text" id="users" class="autocomplete">
<label for="autocomplete-input">Pesquisar</label>
This here is the Route
Route::get('/User/Dados','User\UserController@buscar');
And finishing this one is the Controller
public function buscar(Request $req){
$user_date = $req->all();
$users = User::all();
$result = [];
foreach ($users as $user) {
$result[] = $user['name'];
}
return response()->json($result);}
Thank you Guys!
Would not be
if(q.length > 3)
instead ofif(word.lenght > 3)
exchange the word by q in if?– adventistaam
Dude, you still haven’t done anything =(
– Victor Gabriel
Give a
console.log( data )
to see what displays– adventistaam
Also change the keyup this one
$('#users').on('keyup',function ()
– adventistaam
yes, I had already changed
– Victor Gabriel
I’ll check the console
– Victor Gabriel
From what I’ve seen, you want to check everything in the User table when typing, that’s right?
– adventistaam
yes, I’m willing to do this
– Victor Gabriel
After you switched the word to q you cleared the cache?
– adventistaam
yes, I cleaned up all the cache and it still looks like this
– Victor Gabriel
you tested? or something like that?
– Victor Gabriel