покажите сообщение пока все обещания выполнены - PullRequest
0 голосов
/ 18 апреля 2019

У меня много запросов ajax, и все они заканчиваются, показывают сообщение: «обещания закончились», но я хочу показать сообщение, пока: «Обрабатывается» или «Работает ...», и я не знаю.Я использую JQuery

$("#btnDelete").click(function () {
    var promises = [];
    if (confirm("¿Seguro que quiere borrar?")) {
        $('.delete:checked').each(function (index, value) {
            promesas.push(
                $.ajax({
                    method: "POST",
                    url: "transaccion.php",
                    data: {
                        id_pagos_detalle: $(this).val(),
                        accion: "Registrar_inf_consignacion",
                        estado_elemento: "Si"
                    }
                }).then(function (msg) {
                    if(msg.indexOf("SUCCESS") != -1){
                        console.log("delete this element");
                    }else{
                        alert("ERROR");
                        return false;
                    }
                })
            );  // end promise  
        });

        // process all promises
        $.when.apply($, promises).then(function(){
            alert("Promises ended");
            location.reload(true);
        });
    }
});

1 Ответ

0 голосов
/ 18 апреля 2019

Яроманда Х прав. Вы, вероятно, можете сделать что-то вроде этого:

$("#btnDelete").click(function () {
var promises = [];
if (confirm("¿Seguro que quiere borrar?")) {

   //Loading message here

    $('#you_div').html('Loading...');
    $('.delete:checked').each(function (index, value) {
        promesas.push(
            $.ajax({
                method: "POST",
                url: "transaccion.php",
                data: {
                    id_pagos_detalle: $(this).val(),
                    accion: "Registrar_inf_consignacion",
                    estado_elemento: "Si"
                }
            }).then(function (msg) {
                if(msg.indexOf("SUCCESS") != -1){

                      //hide the loading message
                      $('#you_div').hide();

                    console.log("delete this element");
                }else{
                    alert("ERROR");
                    return false;
                }
            })
        );  // end promise  
    });

    // process all promises
    $.when.apply($, promises).then(function(){



        alert("Promises ended");
        location.reload(true);
    });
}
});

Не забудьте добавить you_div в соответствующее место в вашем html

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...