从ajax中发布后重定向到页面

我想从ajax发布后重定向到动作索引,控制器管理员。

$.post("/Admin/Create", { inputs: inputs, columnsCount: columnsCount, }); 

如何在成功后更改此代码以将其重定向到索引页面?

使用post的第3个参数

 $.post( "/Admin/Create", { inputs: inputs, columnsCount: columnsCount, }, function() { window.location.replace("/Admin/index"); } ); 

虽然window.location.replace或window.location.href肯定window.location.href ,但我鼓励你退后一步,想想是否需要进行Ajax调用!

Ajax用于刷新页面的一部分,当您部分刷新页面时,您不会将用户重定向到其他页面。

因此,如果您仔细考虑,您可以使用常规post替换您的ajaxpost,并将用户重定向到与控制器本身不同的操作。 这样,您还将遵循更清晰的Post-Redirect-Get模式。

 $.post("/Admin/Create", { inputs: inputs, columnsCount: columnsCout }, function(){ window.location.href = "http://..../Admin/Index"; });