相关疑难解决方法(0)

如何在$ .ajax回调中RedirectToAction?

我使用$ .ajax()每5秒轮询一次动作方法,如下所示:

$.ajax({
    type: 'GET', url: '/MyController/IsReady/1',
    dataType: 'json', success: function (xhr_data) {
        if (xhr_data.active == 'pending') {
            setTimeout(function () { ajaxRequest(); }, 5000);                  
        }
    }
});
Run Code Online (Sandbox Code Playgroud)

和ActionResult动作:

public ActionResult IsReady(int id)
{
    if(true)
    {
        return RedirectToAction("AnotherAction");
    }
    return Json("pending");
}
Run Code Online (Sandbox Code Playgroud)

我必须将动作返回类型更改为ActionResult才能使用RedirectToAction(最初它是JsonResult并且我正在返回Json(new { active = 'active' };),但它看起来很难重定向并从$ .ajax()成功回调中呈现新视图.我需要从这个轮询ajax回发中重定向到"AnotherAction".Firebug的响应是来自"AnotherAction"的视图,但它不是渲染.

ajax asp.net-mvc jquery

16
推荐指数
1
解决办法
2万
查看次数

标签 统计

ajax ×1

asp.net-mvc ×1

jquery ×1