没有办法做到同步PageMethods打电话? [英] Any way to do a synchronous PageMethods call?

查看:194
本文介绍了没有办法做到同步PageMethods打电话?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做到这一点:

function DelBatch()
{var userInfo = get_cookie("UserInfo");
PageMethods.DeleteBatchJSWM(userInfo, function(result)
                                          {window.location = "BatchOperations.aspx";});
}

但它仍然异步运行。我需要的浏览器真正等到我的code-后面执行完毕,那么就可以刷新

But it still runs asynchronously. I need the browser to actually wait until my code-behind is finished executing, then it can be refreshed

有装入了刚刚从数据库中删除值的列表框,他们不应该是可见的。问题我已经是code-背后是执行之前的窗口位置刷新,并没有什么好像它已被删除用户。

There's a listbox loaded with values that were just deleted from the database, they shouldn't be visible. Problem I have is the window location refreshes before the code-behind is executed, and nothing seems like it was deleted to the user.

推荐答案

使用jQuery的阿贾克斯,而不是打电话了吗?它具有(异步 ),您可以选择同步/异步模式的可选项: http://api.jquery.com/jQuery.ajax/

Call it using jQuery ajax instead? It features an option (async) where you can select sync/async mode: http://api.jquery.com/jQuery.ajax/

这个优秀的文章将告诉您如何最有效地从jQuery的调用PageMethods:<一href=\"http://encosia.com/using-jquery-to-directly-call-aspnet-ajax-page-methods/\">http://encosia.com/using-jquery-to-directly-call-aspnet-ajax-page-methods/

This excellent article tells you how best to call PageMethods from jQuery: http://encosia.com/using-jquery-to-directly-call-aspnet-ajax-page-methods/

从本质上讲,所有你需要做的是这样的:

Essentially, all you will need to do is this:

$.ajax({
  type: "POST",
  async: false,
  url: "yourpage.aspx/DeleteBatchJSWM",
  data: "{ put json representation of userInfo here }",
  contentType: "application/json; charset=utf-8",
  dataType: "json",
  success: function(msg) {
    window.location = "BatchOperations.aspx";
  }
});

看一个JSON格式的解决方案 Crockford的JSON字符串化

这篇关于没有办法做到同步PageMethods打电话?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆