xai*_*oft 42 c# jquery post jquery-post asp.net-mvc-2
以下内容不会重定向我的页面:这是MVC代码:
[HttpPost]
public ActionResult GoHome()
{
return RedirectToAction("Index", "Home");
}
Run Code Online (Sandbox Code Playgroud)
这是ajax帖子:
$.support.cors = true;
$.ajax({
type: "POST",
url: "http://localhost/UserAccount/GoHome",
dataType: 'json',
crossDomain: true
});
Run Code Online (Sandbox Code Playgroud)
该帖子是成功的,当它与GoHome操作发生冲突时,它不会重定向到Home Controller的Index Action.
Tom*_*mmy 74
您无法从AJAX帖子重定向.您可以返回要将浏览器重定向到的URL,然后从Javascript重定向.
调节器
[HttpPost]
public ActionResult GoHome()
{
return Json(Url.Action("Index", "Home"));
}
Run Code Online (Sandbox Code Playgroud)
使用Javascript
$.ajax({
type: "POST",
url: "http://localhost/UserAccount/GoHome",
dataType: 'json',
crossDomain: true,
success: function (data) {
window.location.href = data;
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
42612 次 |
| 最近记录: |