$.ajax({
url: "/cgi-bin/stats.exe",
method: "post",
async: false,
data: { refresh: "a41" }
});
Using ajax post synchronously - "async: false".
While it blocks the browser during the active request, what is the most efficient way to change the cursor to the hourglass or display a wait .gif?
Perhaps set the cursor as it enters this function then change it back in the success or plete function?
Any advice is appreciated.
Thank You.
$.ajax({
url: "/cgi-bin/stats.exe",
method: "post",
async: false,
data: { refresh: "a41" }
});
Using ajax post synchronously - "async: false".
While it blocks the browser during the active request, what is the most efficient way to change the cursor to the hourglass or display a wait .gif?
Perhaps set the cursor as it enters this function then change it back in the success or plete function?
Any advice is appreciated.
Thank You.
Share Improve this question edited Apr 21, 2010 at 19:47 Matt Ball 360k102 gold badges653 silver badges720 bronze badges asked Apr 21, 2010 at 18:57 T.T.T.T.T.T. 34.7k47 gold badges135 silver badges172 bronze badges 1-
Remove the
async: false
line and then do as Hooray suggested. – Rosdi Kasim Commented Apr 22, 2010 at 1:06
3 Answers
Reset to default 3I haven't tested this, but I think it would be done like so:
$('html, body').css('cursor', 'wait');
$.ajax({
url: "/cgi-bin/stats.exe",
method: "post",
async: false,
data: { refresh: "a41" },
success: function() {
$('html, body').css('cursor', 'auto');
// the rest of your processing here
},
error: function() {
$('html, body').css('cursor', 'auto');
}
});
Per @patrick's suggestion, changed it back on error as well.
Don't make the request synchronous because it will totally block everything else. Instead, you can use an asynchronous request, but make it look like it's synchronous by "blocking" the UI. I use jQuery.blockUI() for this.
I remend using the jQuery blockUI plug-in. It will change the cursor, show any message or icon (http://ajaxload.info/) you like while the user is waiting. There's lots of info on the website for how to use it, but in its simplest form:
$(document).ajaxStart($.blockUI).ajaxStop($.unblockUI);
That will automatically show the wait cursor and prevent user activities until the ajax call pletes.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744287369a4566862.html
评论列表(0条)