我使用$阿贾克斯()以查询操作方法每隔5秒如下:
$.ajax({
type: 'GET', url: '/MyController/IsReady/1',
dataType: 'json', success: function (xhr_data) {
if (xhr_data.active == 'pending') {
setTimeout(function() { ajaxRequest(); }, 5000);
}
}
});
和ActionResult的行动:
public ActionResult IsReady(int id)
{
if(true)
{
return RedirectToAction("AnotherAction");
}
return Json("pending");
}
我不得不改变操作返回类型中的ActionResult为了使用RedirectToAction(原来它是JsonResult,我返回Json(new { active = 'active' };
),但它在重定向和在$ .ajax()成功回调中呈现新视图时遇到问题。我需要在这个轮询ajax回发中重定向到“AnotherAction”。 Firebug的回应是来自“AnotherAction”的视图,但它不是渲染。
发现了另一篇文章中类似的东西经过详尽的搜索。唯一不同的是它使用了window.location.replace。谢谢! – 2010-08-20 22:24:51