php - 在引导模式框中加载远程数据之前添加等待消息

标签 php jquery css twitter-bootstrap-3 bootstrap-modal

我有这段代码可以将远程 php 数据加载到引导模式框中:

$(function() {
    $(window).bind("resize", function() {
        if ($(this).width() < 400) {
            $('#tabs-content').removeClass('col-xs-10').addClass('col-xs-12')
        } else {
            $('#tabs-content').removeClass('col-xs-12').addClass('col-xs-10')
        }
    }).resize();
});
$(function() {  
    $(document).on('click', '.push', function(e) {
        e.preventDefault();
        var id = $(this).attr('id'); 
        $.ajax({
            type: 'post',
            url: 'details.php', // in here you should put your query 
            data: {
                'bookid': id,
                'lang': 'fa',
                'csrf_token': 'MTQ0OTQxNDQ0MUVvN2JwNXNJRHVxMDZmOXFpQm1ROFNNTk1UZ3lPMGZO'
            }, 
            success: function(r) {
                // now you can show output in your modal 
                $('#bookdetails').modal({
                        backdrop: 'static',
                        keyboard: false
                    }) // put your modal id 
                $('.something').show().html(r);
            }
        }); 
    });
});

这对我有用,但我需要在加载数据之前显示加载 message/image

如何添加等待消息/图标?!

最佳答案

您只需要在 Ajax 调用 之前显示 image/message 并将其隐藏在 success: function(r)

假设您有图像要在模态加载之前显示,例如 HTML 图像

<img class="progress" src="http://downgraf.com/wp-content/uploads/2014/09/01-progress.gif" style="display:none;">

在 JS 中,仅使用 .show() 函数显示图像,并且在 success: function(r) 模式加载后使用 .hide( ) 函数

$(document).on('click', '.push', function(e) {
    e.preventDefault();
    var id = $(this).attr('id');
    $(".progress").show(); // <-- Show progress image
    $.ajax({
        type: 'post',
        url: 'details.php', // in here you should put your query 
        data: {
            'bookid': id,
            'lang': 'fa',
            'csrf_token': 'MTQ0OTQxNDQ0MUVvN2JwNXNJRHVxMDZmOXFpQm1ROFNNTk1UZ3lPMGZO'
        }, 
        success: function(r) {
            // now you can show output in your modal 
            $('#bookdetails').modal({
                    backdrop: 'static',
                    keyboard: false
                }) // put your modal id 
            $('.something').show().html(r);
            $(".progress").hide(); // <-- Hide progress image
        }
    });
});

Minimal example with delay and fade

关于php - 在引导模式框中加载远程数据之前添加等待消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34119171/

相关文章:

PHP fatal error : Call to undefined function mysql_query() in CLI on Ubuntu server

php - 带有单数/复数词的 NumberFormatter

php - Num_Rows 中未选择任何数据库

javascript - Rails 中的 Jquery 异步表单提交

javascript - 当输入类型 = 文件框已填充时更改按钮文本

php - Ubuntu 20 终端 PHP 脚本输出

php - Gmail 喜欢使用 jQuery 上传文件

javascript - jQuery/JavaScript 冒泡和停止传播不起作用

html - 折叠框(图像菜单)

css - 在 HTML5 中为 "just text"使用 p 标签是否有充分的理由?