如何在MVC Ajax中使用jQuery blockui外接程序?

时间:2022-11-26 13:30:50

I have been reading the post here:

我一直在这里阅读帖子:

http://encosia.com/2008/10/04/using-jquery-to-enhance-aspnet-ajax-progress-indication/

But it wants to use the following object:

但是它想要使用以下对象:

Sys.WebForms.PageRequestManager.getInstance()

Which doesn't exist when using the MVC AJAX code. Has anyone tried to hook when the postback ends from MVC AJAX to know when to unblock the UI?

使用MVC AJAX代码时不存在。有什么人试图在回发从MVC AJAX结束时知道什么时候解锁UI?

2 个解决方案

#1


1  

There's not really a way to use blockUI as intended with a full round-trip to the server.

实际上没有一种方法可以像往常一样使用blockUI来完成服务器的往返。

If you're using jQuery's $.ajax() or $.getJSON functions to work against the server asynchronously, you could block before the call and then unblock in the "success" handler.

如果您使用jQuery的$ .ajax()或$ .getJSON函数异步处理服务器,则可以在调用之前阻塞,然后在“success”处理程序中取消阻塞。

#2


1  

Dave is right, there's no "MVC" way to do it, but you certainly have access to the ajax events in jQuery. The "setTimeout" call allows us to keep the blockUI hidden if the AJAX call returns in less than 250ms.

Dave是对的,没有“MVC”方法可以做到这一点,但你当然可以访问jQuery中的ajax事件。如果AJAX调用在小于250ms内返回,则“setTimeout”调用允许我们隐藏blockUI。

$().ajaxSend(function() {
  doLoad = setTimeout(function() { 
   $("#divtoblock").block({ message: "Loading..." }); }, 250);
});

$().ajaxComplete(function() {
  clearTimeout(doLoad);
  $("#divtoblock").unblock();
});

#1


1  

There's not really a way to use blockUI as intended with a full round-trip to the server.

实际上没有一种方法可以像往常一样使用blockUI来完成服务器的往返。

If you're using jQuery's $.ajax() or $.getJSON functions to work against the server asynchronously, you could block before the call and then unblock in the "success" handler.

如果您使用jQuery的$ .ajax()或$ .getJSON函数异步处理服务器,则可以在调用之前阻塞,然后在“success”处理程序中取消阻塞。

#2


1  

Dave is right, there's no "MVC" way to do it, but you certainly have access to the ajax events in jQuery. The "setTimeout" call allows us to keep the blockUI hidden if the AJAX call returns in less than 250ms.

Dave是对的,没有“MVC”方法可以做到这一点,但你当然可以访问jQuery中的ajax事件。如果AJAX调用在小于250ms内返回,则“setTimeout”调用允许我们隐藏blockUI。

$().ajaxSend(function() {
  doLoad = setTimeout(function() { 
   $("#divtoblock").block({ message: "Loading..." }); }, 250);
});

$().ajaxComplete(function() {
  clearTimeout(doLoad);
  $("#divtoblock").unblock();
});