Last active
March 10, 2019 01:04
-
-
Save diogenesjup/3c6c89c70f946bcc8648f847df23f227 to your computer and use it in GitHub Desktop.
Exemplo Ajax
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <script type="text/javascript"> | |
| // EXIBIR O PRELOADER | |
| $('#preloader').show(); | |
| // INICIO CHAMADA AJAX | |
| var request = $.ajax({ | |
| method: "POST", | |
| url: "arquivo-que-limpa-a-sessao.php", | |
| data:{nomeVariavel:valorVariavel} | |
| }) | |
| request.done(function (dados) { | |
| // SE A CHAMADA DER CERTO, SERÁ EXECUTADO ESSE BLOCO DE CÓDIGO | |
| // DAI VOCÊ PODE POR AQUI A FUNCAO JAVASCRIPT QUE LIMPA A TELA, EXEMPLO | |
| $('#preloader').hide(); | |
| $("#linhaProdutoX).fadeOut("500"); // AQUI PE UM EXEMPLO | |
| $('#produtos-carrinho').fadeTo("100"); // ESSA AQUI EU COPIEI DO SEU CÓDIGO | |
| }); | |
| request.fail(function (dados) { | |
| // ESSE BLOCO É SE DER ERRADO | |
| $('#preloader').hide(); | |
| alert("Desculpe, não foi possível concluir a operação, tente novamente mais tarde"); // AVISAR O USUÁRIO QUE DEU RUIM | |
| console.log("ERRO ESPECIFICO: "+dados); // AQUI VAMOS AVISAR AO DESENVOLVEDOR O ERRO EXATO, O RETORNO DA CHAMADA ESTÁ NA VARIAVEL DADOS | |
| }); | |
| // FINAL CHAMADA AJAX | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment