Why is my animated GIF not animated when I call an AJAX method?

我的梦境 提交于 2019-12-06 10:17:57

Is this problem only in IE? See this page about IE causing problems with animated gifs. Once the form submit is made your animated gif may get messed up. This page talks about it in depth.

http://www.stillnetstudios.com/animated-in-progress-indicator-for-long-running-pages/

A workaround would be to display the wait after the form submit has been called. Of course if it takes a long time for your AJAX call to process your user will be left wondering what's going on.

try to show it when the user clicks and hiding it after the ajax request finishes.

$(function() {
$("#createButton").click(function(e){
    $('#pleaseWait-dialog').show();
     e.preventDefault();

    var $form = $(this).closest("form");

    $("#pleaseWait-dialog").dialog({
        modal: true,
        height: 200,
        resizable: false,
        draggable: false
    });

    $.ajax({
        type: "GET",
        url: "myScript.cfm",
        async: true,
        success: function() {
            $form.submit();
        }
    });

     return false;
  });
});
Aaron Digulla

To restart the animation, set the src attribute of the image to its current value.

See this answer for code which uses a timeout to restart the animation after a couple of milliseconds.

To make it work in IE insert an iframe with the gif inside, sounds crazy but works.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!