async:false
loadmask で呼び出された jQuery ajax が起動しない場合。ajaxの前に呼び出しても:
$("#d").on("click", function () {
$("#d").mask("Waiting...");
fn();
$("#d").unmask("Waiting...");
});
以下の完全なコード:
<link href="jquery.loadmask.css" rel="stylesheet" type="text/css" />
<script src="jquery-latest.pack.js" type="text/javascript"></script>
<script src="jquery.loadmask.js" type="text/javascript"></script>
<div id="d" style="border: 1px solid red; width: 300px; height: 200px">asdfasdf</div>
<script>
$(function () {
$("#d").on("click", function () {
fn();
});
});
function fn() {
var a = JSON.stringify({
text: 'some text',
array: [1, 2, 'three'],
object: {
par1: 'another text',
par2: [3, 2, 'one'],
par3: {}
}
});
var data = {
json: a,
delay: 3
}
$.ajax({
url: "http://jsfiddle.net/echo/json/",
data: data,
type: "POST",
async: false,
beforeSend: function (response) {
$("#d").mask("Waiting...");
},
success: function (response) {
console.log(response);
},
complete: function () {
$("#d").unmask("Waiting...");
}
});
}
</script>