我想重定向到操作索引,從ajax發佈後的控制器管理員。從ajax發佈後,重定向到一個頁面
$.post("/Admin/Create", { inputs: inputs, columnsCount: columnsCount, });
如何更改此代碼以將其重定向到索引頁後成功?
我想重定向到操作索引,從ajax發佈後的控制器管理員。從ajax發佈後,重定向到一個頁面
$.post("/Admin/Create", { inputs: inputs, columnsCount: columnsCount, });
如何更改此代碼以將其重定向到索引頁後成功?
使用post
$.post(
"/Admin/Create",
{ inputs: inputs, columnsCount: columnsCount, },
function() {
window.location.replace("/Admin/index");
}
);
$.post("/Admin/Create", {
inputs: inputs,
columnsCount: columnsCout
}, function(){
window.location.href = "http://..../Admin/Index";
});
雖然window.location.replace或window.location.href
肯定工作,我鼓勵第三個參數你退後一步,並認爲Ajax調用是否需要在所有!
Ajax用於刷新頁面的一部分,當您部分刷新頁面時,您不會將用戶重定向到其他頁面。
所以,如果你仔細想想,你可以用普通帖子替換你的ajax帖子,並將用戶重定向到控制器本身的不同動作。通過這種方式,您也將遵循更清晰的Post-Redirect-Get模式。
非常感謝,它真的幫助我! – user269431 2010-02-18 12:44:04