我使用$阿賈克斯()以查詢操作方法每隔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