Loading Bar

Asked

Viewed 163 times

1

Hello, how do I create a load bar not need to be a Progress bar, until I receive the return of a function.

      $.ajax(settings).done(function (response) {
                console.log(response);
}
  • 5
  • @Netinhosantos I checked this question, but unfortunately the case is different, in this question they talk about upload and with php, in my case I’m using pure javascript, and I don’t want to take in itself the "time", I just want to show the user that the request to get the answer from the Cielo server.

2 answers

1


Use the library Jqueryblockui, see below the implementation.

$(document).ajaxStart($.blockUI({
  message: ' Carregando... '
})).ajaxStop($.unblockUI);
$.ajax({
  url: "https://httpbin.org/get",
  success: function() {
    console.log("Ajax Concluído")
  }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.blockUI/2.70/jquery.blockUI.js"></script>

0

Utilize beforeSend:

$.ajax({
      url: "sua url",
      beforeSend: function() {
        $('elemento').addClass('.show');//ativa o elemento de carregamento no html
      }
    })
      .done(function( data ) {
          $('elemento').addClass('.hidden');//remove o elemento de carregamento no html
      });

Browser other questions tagged

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