Querying BD after leaving the focus of the input and returning results without refresh?

0

I have a table that has about 30 input fields to perform a posting, for example:

<input type="text" size="8" name="Codigo[]" placeholder="Codigo" maxlength="8" />
<input type="text" size="8" name="Codigo[]" placeholder="Codigo" maxlength="8" />
<input type="text" size="8" name="Codigo[]" placeholder="Codigo" maxlength="8" />
<input type="text" size="8" name="Codigo[]" placeholder="Codigo" maxlength="8" />

So the problem comes up, I do not know anything about jQuery or AJAX, and everything I search on the internet uses examples using them but does not explain what each thing does so I can not adapt to my need. I work with PHP where this form I get in another page in which I will write the data in the BD, but before I need that when a code is entered in the field and given the focus in the next field, it searches in the BD the equipment referring to that one code and return the result in a field next to it, successively for each of the fields, which are exactly the same as the example above!

    
asked by anonymous 17.03.2017 / 18:39

1 answer

1

You can do this as follows:

When you leave the field, it sends a request for ajax to a php page, it in turn fetches the data as needed and returns to ajax, which adds the data on the screen as desired, following example:

    //dispara um evento quando sair do campo
    $(".codigo").blur(function(){
    //envia uma requisição por post passando como parâmetro o codigo digitado.
         $.get("enderço da sua página php?codigo="+$(this).val(), 
         function(dados){
          //dados retornados pelo php adicionados na tela onde desejar
          $(dados).appendTo('body');
       })
    })

All you need to do in php is to mount the html with the data you want to add on the screen:

Receive data by $_GET["codigo"] - > bank search - > mount html - > soon

The ajax in this way I said will do the same thing that the browser would do when we access the page directly, returning all the html generated by php.

    
17.03.2017 / 19:14