javascript - How do I change the cursor during a jQuery synchronous browser blocking POST? - Stack Overflow

$.ajax({url: "cgi-binstats.exe",method: "post",async: false,data: { refresh: "

   $.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
Add a ment  | 

3 Answers 3

Reset to default 3

I 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条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信