Ajax Questions in Updates

Asked

Viewed 45 times

-1

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

1 answer

2


In short, 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 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 to use 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();
     }
}); 

  • 1

    Thanks! On an administrators page it is good to make use of this type of method?

  • 2

    It depends on the case , friend, there is no fixed rule for this no. But a poorly done ajax causes slowness. Hugs

Browser other questions tagged

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