Put time to beforeSend and Success

0

you can set the time before send, that is to say at least that the load of the beforeSend takes 1sec, and then after the success I want to close the modal and it will have to have a lapse of time. Try with the timeout but do nothing ...

     $(function(){
          $("#formulario").on("submit", function(e){
              e.preventDefault();
              var f = $(this);
              var formData = new FormData(document.getElementById("formulario"));
              formData.append("dato", "valor");

              $.ajax({
                  url: "datos.php",
                  type: "post",
                  dataType: "html",
                  data: formData,
                  cache: false,
                  contentType: false,
                  processData: false,


                   beforeSend: function(){
                    $("#mensaje").html("<div class='ui active inline loader myLoader'></div>")
                    },
                   timeout:200000,

                   success: function (resultado){
                     $("#mensaje").html(resultado);

                  }

                });
             });
          });
    
asked by Miguel 24.09.2018 в 07:37
source

1 answer

0

In Ajax , just as you are doing, you can not put a wait time at beforeSend . And considering that you need the result to be able to show it, I think you have no choice but to put the timeout in success .

Here is an example of what it would be like.

$(function(){
          $("#formulario").on("submit", function(e){
              e.preventDefault();
              var f = $(this);
              var formData = new FormData(document.getElementById("formulario"));
              formData.append("dato", "valor");

              $.ajax({
                  url: "datos.php",
                  type: "post",
                  dataType: "html",
                  data: formData,
                  cache: false,
                  contentType: false,
                  processData: false,


                   beforeSend: function(){
                    $("#mensaje").html("<div class='ui active inline loader myLoader'></div>")
                    },
                   timeout:200000,

                   success: function (resultado){

                     setTimeout(function(){ $("#mensaje").html(resultado); }, 1000);    
                  }

                });
             });
          });

This will cause when you get the results wait a second before changing the text of #mensaje

    
answered by 24.09.2018 / 08:10
source