0
function purchase() {
    var url = '<%: Url.AbsoluteRouteUrl("packages", new { action = "PrePaidPurchaseWithStoredCc", controller = "packages" })%>';
    $.ajax({
          type: "GET",
          url: url,
          dataType: 'json',
          cache: false,
          data: { ownerKey: selOwnerKey, providerKey: selProviderKey, packageKey: selPackageKey, creditCardId: $("#creditCardId").val(), embedded: true },
          success: function (response) {
           window.location = Sys.Url.route('packages', { action: "provider", controller: "packages", providerKey: '<%: Model.Provider.Key %>', ownerKey: '<%: Model.Owner.Key %>' });
            }
         });
       }

我需要在成功回调时加载整个表单。但不幸的是,上面的代码不起作用。当我window.location在 ajax 调用之前放置代码时它正在工作。

为什么上面的方法不起作用?

4

1 回答 1

0

错误的处理方法如下:

  [HttpGet]
    public ActionResult PrePaidPurchaseWithStoredCc(string ownerKey, string providerKey)
     {   
      return RedirectToAction("Provider", new { providerKey = providerKey, ownerKey = ownerKey });
     }

当我将其更改为如下所示时。它正在工作:

[HttpGet]
public ActionResult PrePaidPurchaseWithStoredCc(string ownerKey, string providerKey)
  {   
    return Json(string.Empty, JsonRequestBehavior.AllowGet);
  }

页面重新加载jQuery 函数如下:

function purchase() {
    var url = '<%: Url.AbsoluteRouteUrl("packages", new { action = "PrePaidPurchaseWithStoredCc", controller = "packages" })%>';
    $.ajax({
          type: "GET",
          url: url,
          dataType: 'json',
          cache: false,
          data: { ownerKey: selOwnerKey, providerKey: selProviderKey, packageKey: selPackageKey, creditCardId: $("#creditCardId").val(), embedded: true },
          success: function (response) {
           window.location = Sys.Url.route('packages', { action: "provider", controller: "packages", providerKey: '<%: Model.Provider.Key %>', ownerKey: '<%: Model.Owner.Key %>' });
            }
         });
       }

注意: 问题是我的操作方法没有 json return.B'cos,它不会触发 .success: 方法。

于 2013-04-11T13:36:33.547 回答