Ajax定位方法不加载表单

本文关键字:加载 表单 方法 定位 Ajax | 更新日期: 2023-09-27 18:08:50

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调用它的工作。

为什么上面的方法不工作?

Ajax定位方法不加载表单

错误操作方法如下:

  [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返回。因为它不会触发。success:方法。