RedirectToAction成功jQuery的阿贾克斯后后不工作? [英] RedirectToAction not working after successful jquery ajax post?

查看:194
本文介绍了RedirectToAction成功jQuery的阿贾克斯后后不工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下不重定向我的网页:这里是MVC code:

The following does not redirect my page: Here is the MVC code:

    [HttpPost]
    public ActionResult GoHome()
    { 
         return RedirectToAction("Index", "Home");   
    }

下面是ajax的职位:

Here is the ajax post:

   $.support.cors = true;

            $.ajax({
                type: "POST",
                url: "http://localhost/UserAccount/GoHome",
                dataType: 'json',
                crossDomain: true
            });

该职位是成功的,当它hists的GOHOME行动不重定向到家庭控制器的索引动作。

The post is successful and when it hists the GoHome action it does not redirect to the Index Action of the Home Controller.

推荐答案

您无法从AJAX后重定向。你可以返回URL要重定向浏览器却和JavaScript重定向。

You cannot redirect from an AJAX post. You could return the URL you want to redirect the browser to however and redirect from Javascript.

控制器

[HttpPost]
public ActionResult GoHome()
{ 
     return Json(Url.Action("Index", "Home"));   
}

的JavaScript

        $.ajax({
            type: "POST",
            url: "http://localhost/UserAccount/GoHome",
            dataType: 'json',
            crossDomain: true,
            success: function(data){
                window.location.href = data;
            }
        });

这篇关于RedirectToAction成功jQuery的阿贾克斯后后不工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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