为jquery ajax请求增加正在运行提示

时间:2023-03-09 18:59:10
为jquery ajax请求增加正在运行提示

在jquery源码中增加showMask()方法调用:

if ( xhrSupported ) {

jQuery.ajaxTransport(function( options ) {
// Cross domain only allowed if supported through XMLHttpRequest
if ( !options.crossDomain || support.cors ) {

var callback;

return {
send: function( headers, complete ) {

showMask();

......

在jquery源码中增加hideMask()方法调用:

// Callback for when everything is done
function done( status, nativeStatusText, responses, headers ) {
//alert(1);
hideMask();
var isSuccess, success, error, response, modified,
statusText = nativeStatusText;

// Called once
if ( state === 2 ) {
return;
}

......

//调用的是easyui的效果

// Load
function showMask() {
$("<div class=\"datagrid-mask\"></div>").css({ display: "block", width: "100%", height: $(window).height() }).appendTo("body");
$("<div class=\"datagrid-mask-msg\"></div>").html("正在运行,请稍候。。。").appendTo("body").css({ display: "block", left: ($(document.body).outerWidth(true) - 190) / 2, top: ($(window).height() - 45) / 2 });
}
// hidden Load
function hideMask() {
$(".datagrid-mask").remove();
$(".datagrid-mask-msg").remove();
}

参考文件: