0

Good day all,

I have a loading image that is shown every time a contact form is submitted. I am using jQuery Ajax to submit data to the server and I am using the following code to show the image.

$(document).ajaxStart(function(){
    $("#loading").show();

}).ajaxStop(function(){
    $("#loading").hide();
});

I also have a div (not included in the contact form) that loads data automatically every 3 seconds from the database. Now every 3 seconds, the loading image is shown. That is really annoying for the user.

My question is.. how to make the loading image only to appear when the form is submitted but not when the div refreshes automatically.

Thank you for your time.

Update By using global:false in ajax, fixed my problem... thanks!

rob
  • 715
  • 2
  • 6
  • 20

1 Answers1

0

Perhaps you should move your $("#loading") toggle to your form submission script? Like this:

form.submit(function(e){
    e.preventDefault();
    $("#loading").toggle();
    $.ajax(...).done(function(){
        $("#loading").toggle();
    });
})
Eternal1
  • 5,447
  • 3
  • 30
  • 45