dscizpq790832708 2013-05-12 09:30
浏览 47

AJAX和blockUI

I want to show "wait" message with plugin http://www.malsup.com/jquery/block/. ajax.php file is

<?php
sleep(2);
$arr = array('m' => 'OK');
echo json_encode($arr);
?>

And jquery code is

function block() {
    $.blockUI();
    $.ajax({
        type: 'POST',
        dataType: 'json',
        url: 'ajax.php',
        async: false,
        data: {},
        success: function(data) {
            $.unblockUI();
        }
    });
}
block();
$('#button').click(function() {block();});

How to show a "loading.."-message BEFORE of using ajax for getting "OK" and hide AFTER of using ajax? Now it shows and hides after using. I need also "async: false," in ajax json. Also that this block show two seconds.

Thanks

  • 写回答

1条回答 默认 最新

  • duanke9540 2013-05-12 09:39
    关注

    In jquery ajax their is a property called 'beforeSend' use that like this

    $.ajax({
        type: 'POST',
        dataType: 'json',
        url: 'ajax.php',
        async: false,
        data: {},
        beforeSend: function(){
            showLoadingScreen();
        },
        success: function(data) {
            alert(data.m);
    
        },
        complete: function(data){
    
             $.unblockUI();
        }
    });
    
    function showLoadingScreen()
    {
        //include block.js for using this
        $.blockUI({ 
            message: 'Loading....',
            css: { 
                border: 'none',
                width: '300px', 
                height: '50px',
                padding: '15px',
                backgroundColor: '#000', 
                '-webkit-border-radius': '10px', 
                '-moz-border-radius': '10px', 
                opacity: .5, 
                color: '#fff'
            }       
        }); 
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向