Ajax doubts in updates

0

Good morning! I would like to know how Ajax technology works, if it is possible I make a code in php and call it through an ajax, type an query, would I put the answer file on one page and the php on another with ajax? How does it work, could you explain? I did not find it very well on the internet. Thank you in advance.

    
asked by anonymous 11.09.2018 / 14:39

1 answer

2

In summary, this is when you, in this case, make requests to communicate with server-side scripts using HTTP requests.

This server-side script, in your case, is a PHP code.
The advantage of using is that through this request you do not need to reload your page.

There are several ways to do it, but one of the most common ways is using jquery, according to the code below:

$.ajax({
    type: 'POST', // Aqui é o método HTTP
    dataType: 'json', // Aqui é o formato do retorno do script php logo abaixo
    url: 'salvar.php', // Este é o seu script PHP do lado do servidor
    data: dados, // Aqui são os dados que você vai enviar pelo metodo notificado acima, no caso POST, para o seu script salvar.php
    success: function(response) { // aqui é o tratamento do retorno do script salvar.php. O success indica que o script retornou o código 200, ou seja, foi encontrado e executado sem erros
          location.reload();
     }
}); 
    
11.09.2018 / 14:50