注意把async改为true即可
$.ajax({
url: '#',
type: 'post',
async: true,
contentType: "application/json",
beforeSend: function(){
$("<p class=\"datagrid-mask\"></p>").css({ display: "block", width: "100%", height: $(window).height() }).appendTo("body");
$("<p class=\"datagrid-mask-msg\"></p>").html("正在运行,请稍候...").appendTo("body").css({ display: "block", left: ($(document.body).outerWidth(true) - 190) / 2, top: ($(window).height() - 45) / 2 });
},
complete: function(){
$(".datagrid-mask").remove();
$(".datagrid-mask-msg").remove();
},
success: function (data) {
alert("执行成功");
}
})