update does not work after ajax request

Asked

Viewed 72 times

1

good personal evening I am creating a system and in it I make a dynamic request with ajax to fetch names of customers I have a link that opens a modal with the information to give update ,as when I click Refresh the page

function exibirConteudo(id) {

            $('#myModal').modal('show');    

    // Verificando Browser
if(window.XMLHttpRequest) {
   req = new XMLHttpRequest();
}
else if(window.ActiveXObject) {
   req = new ActiveXObject("Microsoft.XMLHTTP");
}

// Arquivo PHP juntamento com a id da noticia (método GET)
var url = "liks.php?recordID="+id;

    req.open("GET", url, true);

    req.onreadystatechange = function() {

    // Exibe a mensagem "Aguarde..." enquanto carrega
    if(req.readyState == 1) {
        document.getElementById('conteudoModal').innerHTML = 'Aguarde...';
    }

        if(req.readyState == 4 && req.status == 200) {

    // Resposta retornada pelo exibir.php
    var resposta = req.responseText;

    // Abaixo colocamos a resposta na div conteudo
    document.getElementById('conteudoModal').innerHTML = resposta;
    }
}
req.send(null);


}

this is my save button that opens in modal

<input type="hidden" name="id_cli"  value="<?php echo $row['id_cli']; ?>" />
           <button class="btn btn-success" name="submit" type="submit">
        Salvar
       </button>
    </form>

and this is my ajax request for the save button

$("#form_cli").submit(function(e) {
    var url2 = "con_cliente.php" 
    var url = "update/update_cli.php"; 
     if (confirm('Tem certeza que quer cadastrar o cliente?')){ 

    $.ajax({
           type: "POST",
           url: url,
           data: $("#form_cli").serialize(),
           success: function(data)
    {

        $("#alterafade").fadeOut(800, function(){
                            $("#alterafade").load(url2).fadeIn().delay(2000);
               });

               //utilizar o dado retornado para alterar algum dado da tela.
           }

         });
     }

    e.preventDefault();// esse comando serve para previnir que o form realmente realize o submit e atualize a tela.
});

that’s how my modal is inserir a descrição da imagem aqui

When I click to save it from refresh and the page address is the way it is

1 answer

0

By analyzing your code you are using the method GET to search for customer names, and this using the method post to update. The correct method to make a update is the PUT Requires a resource to be "stored" in the given URI. If the resource already exists, it must be updated. If it does not exist, it can be created. If you use the POST The method tries to create a new record and does not change it.

Browser other questions tagged

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