Jquery - Perform a function within another function

0

Use the SweetAlert2 alert ( link ).

With it, there is a function that deletes an item:

$(document).ready(function(){
    readProducts(); /* it will load products when document loads */

    $(document).on('click', '#delete_product', function(e){
        var productId = $(this).data('id');
        SwalDelete(productId);
        e.preventDefault();
    });
});

function SwalDelete(productId){
    swal({
        title: 'Confirma excluir a empresa?',
        text: "Não será possível reverter a ação!",
        type: 'warning',
        showCancelButton: true,
        confirmButtonColor: '#ec2e54',
        cancelButtonColor: '#bbb1af',
        confirmButtonText: 'Sim, excluir',
        cancelButtonText: "Cancelar",
        showLoaderOnConfirm: true,

        preConfirm: function() {
            return new Promise(function(resolve) {

                $.ajax({
                    url: '/includes/excluir_empresa.php',
                    type: 'POST',
                    data: 'delete='+productId,
                    dataType: 'json'
                })
                .done(function(response){
                    swal('Excluído!', response.message, response.status);
                    readProducts();
                })
                .fail(function(){
                    swal('Oops...', 'Algo deu errado com o Ajax !', 'error');
                });
            });
        },
        allowOutsideClick: false     
    }); 
}

function readProducts(){
    $('#carragar_itens').load('/loads/carregar_empresas.php?cod_cli=<?php echo $codLogin; ?>&tam=<?php echo $width; ?>'); 
}

HTML:

<div id="carragar_itens"></div> <!-- products will be load here -->

I believe that by using .load , there is a problem: before installing this alert, this page also had a popover :

$("[data-toggle=popover]").popover()

Now the SweetAlert2 alert works, but popover no longer works.

Is it possible to execute more than one function with jQuery?

    
asked by anonymous 24.05.2017 / 14:33

0 answers