Do real-time bank search

3

How can I do it in PHP so that when the user types in the search field it will already appear the records of the database.

For example, supposing that it is a city register, the user type "Field", the records "Campo Grande, Campo Largo, Campo Mourão ..." should appear immediately at the time of typing. >

Is it too complex to do this?

    
asked by anonymous 24.10.2017 / 18:05

1 answer

4

You can call the output via ajax and create an autocomplete list using the Vanilla Javascript AutoComplete

You will autocomplete the callback in Javascript:

function ShowModalRelMapaAeronave() {
    $.ajax({
        type: 'POST',
        url: BASE_SITE + '/Projeto/Projeto/BuscarAeronaves',
        data: {  },
        success: function (data) {

            new autoComplete({
                selector: '#TxtAeronave',
                minChars: 2,
                source: function (term, suggest) {
                    term = term.toLowerCase();
                    var choices = data;
                    var matches = [];
                    for (i = 0; i < choices.length; i++)
                        if (~choices[i].toLowerCase().indexOf(term)) matches.push(choices[i]);
                    suggest(matches);
                }
            });

            $('#modalRelMapaAeronave').modal('show');
        }
    });
}

Here in the case I call the post in a route, I get the return and put in a txt of my html, so when it goes typing goes autocompleting. It is necessary to add the javascript and css library.

The route is responsible for making the query.

    
24.10.2017 / 18:20