6

I want to show ajax loading image. but don't know how to do that. here is my working ajax script. please help me to integrate ajax loading gif.thanks

$(function() { 
    $( "#slider" ).slider({ 
       stop: function(event, ui) {
              $.ajax({
              url: "ajax.php",
              cache: false,
              async: false,
             data: "",
                  success: function(html){
                $("#result_list").html(html);
              }
            });

         }
    });
});
1
  • You should consider making your request asynchronous. Commented May 26, 2011 at 5:38

5 Answers 5

6
$(function() { 
$( "#slider" ).slider({ 
   stop: function(event, ui) {
          $("#place_of_loading_image").show();
          $.ajax({
          url: "ajax.php",
          cache: false,
          async: false,
          data: "",
          success: function(html){ //got the data

            $("#place_of_loading_image").hide(); // hide ajax loader         
            $("#result_list").html(html);        // show downloaded content
          }
        });

     }
    });
});

Where #place_of_loading_image is some container (like div), in a place you would like loader.gif to appear.

<div id="place_of_loading_image" style="display:none"><img src="load.gif"/></div>
Sign up to request clarification or add additional context in comments.

2 Comments

this script is working fine in firefox. but not in opera,chrome, ie. please help me thanks
I edited the post. With this variant you can first remove 'style="display:none"' and see that this image is correctly displayed for all browsers.
2

Have you looked at blockui? http://jquery.malsup.com/block/

$(function() { 
    $( "#slider" ).slider({ 
       stop: function(event, ui) {
          $.blockUI({ message: null });  //loading
              $.ajax({
              url: "ajax.php",
              cache: false,
              async: false,
             data: "",
                  success: function(html){
                  $.unblockUI(); //loading complete
                $("#result_list").html(html);
              }
            });

         }
    });
});

Comments

1

Ajax have api ajax start and ajax stop, when ever an ajax request is send this apis triggers

 $(document).bind("ajaxStart.mine", function() {
      $("#image").html("<img src="loading.gif"/>");
    });

$(document).bind("ajaxStop.mine", function() {
  $("#image").html("");
});

Show and Hide your image using classes.

Comments

0

Before you start your XHR, show the loading image.

On the success callback of your XHR, hide the loading image.

Comments

0

Something like this will help.

At start of your function:

jQuery('#processing').html( '<img src="/images/ajaxBigFlower.gif">' );
$('#submit').attr("disabled", true);

In success part of your function:

jQuery('#processing').html( '' );
$('#submit').attr("disabled", false);

Note: <div id='processing'></div> should be in your HTML and you can set the position of this DIV anywhere on page using css. And set id='submit' for these submit buttons that you want to set as disabled when it is processing...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.