Jquery - Run a function within another function

Asked

Viewed 540 times

0

I use the Sweetalert2 alert (https://limonte.github.io/sweetalert2).

With it, there is a function that excludes 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 the .load, there is a problem: before installing this alert, this page had a can also:

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

Now the Sweetalert2 alert works, but the can doesn’t work anymore.

It is possible to execute more than one function with jQuery?

  • It wouldn’t just be putting in the code of popover within the jQuery function?

  • There is a syntax error here: #carragar_items, maybe this is it?

  • I already put it inside the function. It does not load... The script works, there is no syntax error. The problem appeared in not executing the other function that already worked, along with this script.

No answers

Browser other questions tagged

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