Add loader in ajax

0

How can I add a loader to my ajax request?

$(document).on('click', '#reg-discagem input[type="submit"]', function(e){

                  e.preventDefault(); 
var form = $('#reg-discagem');
            $.ajax({
                url: 'EnviarPedidoChamada.php',
                type: 'POST',
                data: form.serialize() 
            })
            .done(function(data){
                $('#form-content_discagem').fadeOut('slow', function(){
                    $('#form-content_discagem').fadeIn('slow').html(data);
                });
            })
            .fail(function(){
                alert('Ajax Submit Failed ...');    
            });
});
    
asked by anonymous 01.02.2018 / 20:35

2 answers

-1

Good afternoon,

I got this way in my application.

link

    
01.02.2018 / 20:39
2

Using ajax is even more difficult, I particularly prefer using jquery form

This is the documentation link

link

The code to send would look like this ...

$('#material_form').ajaxForm({

  beforeSend: function() {        
     // $("#material_form").fadeOut(0);
     // $("#carregando_envio_material").fadeIn(0);
     // $("#progresso_envio_mateial").html("0%");
     //$("#msg_erro_envia_material").html("");    
  },
  uploadProgress: function(event, position, total, percentComplete) {

  //aqui fica a % do load.... voce pode dar o fadin e fad outa nas divs para 

  //aparecer so a partocentagem
  //$("#progresso_envio_mateial").html(percentComplete+"%");
  console.log(percentComplete);

  },
  success: function() {

  },
  complete: function(xhr) {

    //status.html(xhr.responseText);
    data = xhr.responseText;
    console.log(data);


    if(data == "sucesso"){

    }else{

    }
  }
});

Anything, if this is not the correct documentation This is the link from my escript. link

copy the code and create it in your files that will work

    
01.02.2018 / 21:57