jQuery autocomplete with local API

Asked

Viewed 21 times

0

I created an input text and through jQuery I am making an autocomplete, I was able to make it work by putting local data, as I do to show the data of an API generated as localhost. I don’t know how to change it.

Follows my code:

<!-- Importado os arquivos do Jquery -->
<link rel="stylesheet" 
href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>

<!-- Criando um input que receberá o autocomplete -->
<input type="text" id="fruta" placeholder="Informe um esporte"/>

<!-- Meu código Jquery em um arquivo que chamei de fruta.js -->
<script>
   $(function() {
       var frutas = ["Ameixa", "Amora", "Banana", "Uva", "Maça"];
       $("#fruta" ).autocomplete({
           source: frutas
   });
});
</script>

As I said, it works by getting the information locally. I’m looking for and can’t find anything like my situation.

Now I need to exchange it to get information from this API created: http://localhost:5000/frutas

How can I make this trade ?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.