javascript - How to show processing animation / spinner during ajax request? -


i want basic spinner or processing animation while ajax post processing. i'm using jquery , python. looked @ documentation can't figure out put ajaxstart , ajaxstop functions.

here js:

    <script type="text/javascript">       $(function() {           $('.error').hide();           $("#checkin-button").click(function() {            var mid = $("input#mid").val();           var message = $("textarea#message").val();           var facebook = $('input#facebook').is(':checked');           var name = $("input#name").val();           var bgg_id = $("input#bgg-id").val();           var thumbnail = $("input#thumbnail").val();           var datastring = 'mid='+mid+'&message='+message+'&facebook='+facebook+'&name='+name+'&bgg_id='+bgg_id+'&thumbnail='+thumbnail;             $.ajax({               type: "post",               url: "/game-checkin",               data: datastring,               success: function(badges) {               $('#checkin-form').html("<div id='message'></div><div id='badges'></div>");               $('#message').html("<h2><img class=\"check-mark\" src=\"/static/images/check-mark.png\"/>you checked in!</h2>");               $.each(badges, function(i,badge) {               $('#badges').append("<h2>new badge!</h2><p><img class='badge' src='"+badge.image_url+"'><span class='badge-title'>"+badge.name+"</span></p>");               });           }        });        return false;      });       });   </script> 

 $.ajax({               type: "post",               url: "/game-checkin",               data: datastring,               beforesend: function() {                 ... initialization code here (so show loader) ...             },             complete: function() {                 ... finalization code here (hide loader) ...             },             success: function(badges) {               $('#checkin-form').html("<div id='message'></div><div id='badges'></div>");               $('#message').html("<h2><img class=\"check-mark\" src=\"/static/images/check-mark.png\"/>you checked in!</h2>");               $.each(badges, function(i,badge) {               $('#badges').append("<h2>new badge!</h2><p><img class='badge' src='"+badge.image_url+"'><span class='badge-title'>"+badge.name+"</span></p>");   }); 

http://api.jquery.com/jquery.ajax/:

here callback hooks provided $.ajax():

beforesend callback invoked; receives jqxhr object , settings map parameters. error callbacks invoked, in order registered, if request fails. receive jqxhr, string indicating error type, , exception object if applicable. built-in errors provide string exception object: "abort", "timeout", "no transport". datafilter callback invoked upon successful receipt of response data. receives returned data , value of datatype, , must return (possibly altered) data pass on success. success callbacks invoked, in order registered, if request succeeds. receive returned data, string containing success code, , jqxhr object. complete callbacks fire, in order registered, when request finishes, whether in failure or success. receive jqxhr object, string containing success or error code.

note beforesend , complete method additions code.

hope helps.


Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -