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 %>' });
}
});
}
我需要在成功回调时加载整个表单。但遗憾的是上面的代码无法正常工作。当我在ajax调用之前放置window.location
代码时它正在工作。
为什么以上方式不起作用?
答案 0 :(得分: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:方法。