Synchronize 3 Select with Loading + Jquery/ Ajax

Asked

Viewed 142 times

2

Hello, good day.

I am with my app here on the following question.

have the page index.html, on this page I have a <div> so that the loading according to the code below:

<div id="loader" style="display: none;"> <img src="loading.gif" align="center" width="200" height="180">Carregando...</div>

Now I have the js file.

 function onCarregaFunVeiEqu () {

    $.ajax({
        url: ''''''''getFun.php'''''''',
        type: ''''''''get'''''''',
        async: false,
        beforeSend: function(){
            $("#loader").show();
            $("#loader").css({display:"block"});
        },
        success: function(response){
            var obj = JSON.parse(response);
                obj.forEach(function (o, index) {
                    onSincFun(o.cdfun, o.nmfun, o.nusen, o.nmatri);
                });


            $.ajax({
                url: ''''''''getVei.php'''''''',
                type: ''''''''get'''''''',
                async: false,
                success: function(response){
                    var obj = JSON.parse(response);
                        obj.forEach(function (o, index) {
                        onSincVei(o.cdve, o.nuplaca, o.detip, o.demdl);
                    });



                    $.ajax({
                        url: ''''''''getEquipe.php'''''''',
                        type: ''''''''get'''''''',
                        async: false,
                        success: function(response){
                            DeleteEqu();
                            var obj = JSON.parse(response);
                                obj.forEach(function (o, index) {
                                    onSincEqu(o.cdequ, o.deequ, o.dearea, o.nmobra);
                                });
                        }
                    });     
                }

            });
        },
        complete: function(data){
            //$("#loader").hide();

        }
    }).always (function() {
        $("#loader").show();
        $("#loader").css({display:"block"});
    }).done (function() {
        $("#loader").hide();
        $("#loader").css({display:"none"});
    });

}

what happens is :

the Loading.. it looks, but already gone... And in the meantime, he’s synchronizing.. that is to say he had to synchronize EVERYTHING and then disappear Loading...

someone has a suggestion?

1 answer

0


The problem is that you set the Hide conditions at the end of the first ajax request, and are 3

Try this:

function onCarregaFunVeiEqu () {

$.ajax({
    url: ''''''''getFun.php'''''''',
    type: ''''''''get'''''''',
    async: false,
    beforeSend: function(){
        $("#loader").show();
        $("#loader").css({display:"block"});
    },
    success: function(response){
        var obj = JSON.parse(response);
            obj.forEach(function (o, index) {
                onSincFun(o.cdfun, o.nmfun, o.nusen, o.nmatri);
            });


        $.ajax({
            url: ''''''''getVei.php'''''''',
            type: ''''''''get'''''''',
            async: false,
            success: function(response){
                var obj = JSON.parse(response);
                    obj.forEach(function (o, index) {
                    onSincVei(o.cdve, o.nuplaca, o.detip, o.demdl);
                });



                $.ajax({
                    url: ''''''''getEquipe.php'''''''',
                    type: ''''''''get'''''''',
                    async: false,
                    success: function(response){
                        DeleteEqu();
                        var obj = JSON.parse(response);
                            obj.forEach(function (o, index) {
                                onSincEqu(o.cdequ, o.deequ, o.dearea, o.nmobra);
                            });
                    }
                }).done (function() {
                   $("#loader").hide();
                   $("#loader").css({display:"none"});
                });     
            }

        });
    },
    complete: function(data){
        //$("#loader").hide();

    }
    }).always (function() {
        $("#loader").show();
        $("#loader").css({display:"block"});
    }).done (function() {
        //$("#loader").hide();
        //$("#loader").css({display:"none"});
    });

I commented on the code that hides the loading div, and put it at the end of your last request.

the .done() executes at the end of the request

and $("#loader").hide(); hides the Download

  • how can I make "Loading" visible until the end ? I’ve done it separately... Had created 3 Function.. with Sync = False; also didn’t work out. Then I did 3 Function with Sync = True; , too. plus what I know is not very good to let Sync = false. as it can "freeze" the user screen.

  • looks like it worked! Thanks, missed rsrs... I was banging my head for 3 days... already taking advantage of the hook. has something here forum or example... I don’t know the name, of getting the entire screen "locked/ blurred" and loading loading ...

Browser other questions tagged

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