$(function () { $.ajaxLoading = function (options) { var img = $("#progressImgage"); var mask = $("#maskOfProgressImage"); var complete = options.complete; options.complete = function (httpRequest, status) { img.hide(); mask.hide(); if (complete) { complete(httpRequest, status); } }; options.async = true; img.show().css({ "position": "fixed", "top": "50%", "left": "50%", "margin-top": function () { return -1 * img.height() / 2; }, "margin-left": function () { return -1 * img.width() / 2; } }); mask.show().css("opacity", "0.1"); $.ajax(options); }; });