After searching with keyup () edit in Modal and return list with edited value?

0

Good evening guys I'm doing a search with jQuery and the keyup () event like this:

$('#colaborador').keyup(function(){

    var txtInput = $('#colaborador').val();

    if(txtInput.length == 0){
        $('#listPhone').html('');
        return;
    }

    var html = '';

    $.ajax({
        url : "paginas/listPhone.php",
        type : "GET",
        data : {busca: txtInput},
        dataType : "json",
        success : function(data){
            var html = "";
            for (var i = 0; i < data.length; i++) {
                html += '<tr>';
                html += ...
                html += '</tr>';
            }
            $("#listPhone").html(html);
        }
    });
});

So far everything goes well, with each typed letter my script goes into the database and returns a JSON with the lines of the searched content, no problem.

After the return I open a modal with a form inside, also without problems!

To save the edit I make in this form I use the following code:

$('#salvar').click(function() {
    var dados = $('#myForm01').serialize();
    $.ajax({
        type: 'POST',
        dataType: 'json',
        url: 'paginas/editarRamal.php',
        async: true,
        data: dados,
        success: function(response) {
            location.reload(); //DÚVIDA AQUI
        }
    });
    return false;
});

I am doing a reload of the page, but I would like to know how I would do to when clicking the record button go back to the displayed list only with the new value in the edited field.

    
asked by anonymous 06.07.2016 / 00:07

1 answer

0

Location.reload () refreshes the current page. If you use this function you will lose the data on the page. In this case I advise not to use reload. Try this: $ ('# save'). click (function () {     var data = $ ('# myForm01'). serialize ();     $ .ajax ({         type: 'POST',         dataType: 'json',         url: 'pages / editRamal.php',         async: true,         data: data,         success: function (response) {             $ ("# collaborator"). val (response); // and if you want you close the modal here with: // $ ("seumodal"). modal ("hide");         }     });     return false; });

    
06.07.2016 / 03:18