且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

GIF 加载程序图像在 ajax 调用期间没有动画

更新时间:2023-12-05 10:39:52

由于 ajax 请求是 asynchronous 加载的显示并立即再次隐藏.使用 ajaxcomplete 回调来隐藏加载器.

As ajax request is asynchronous the loaded is shown and hid again immediately. Use complete callback of ajax to hide the loader.

检查下面突出显示的代码:

Check the highlighted code below:

$('#checkqar').on('click', function() {
    $("#loading").css("display", "block");
    $.ajax({
        type: "GET",
        url: "http://sss.com/eee",
        crossDomain: true,
        jsonpCallback: 'callback',
        contentType: "application/json; charset=utf-8",
        dataType: "jsonp",
        success: function(msg) {
            //do something
        },
        complete: function() {
            $("#loading").css("display", "none");
            // Use it here
        }
    });

});