在mvc应用程序中调用ajax后重写url
有没有办法在ajax调用后更改url?我有一个页面(例如,url - xyz.com/employees)显示所有员工,并且页面上有一个名为“添加员工”的链接,该链接返回部分视图。由于这是一个ajax调用,url保持不变,返回部分视图后是否可以将url更改为xyz.com/addemployee?
Is there any way to change the url after an ajax call. I have a page (eg., url - xyz.com/employees) which displays all the employees, and there is a link on the page named 'Add Employee' which returns a partial view. As this being an ajax call, the url remains the same, is there anyway to change the url to xyz.com/addemployee after returning the partial view??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
许多 AJAX 应用程序(例如 gmail)使用 url 的井号标签 (#) 部分来实现此目的。您可以使用
document.location
使用 javascript 更改 url。只要主题标签之前的 URL 部分保持不变,页面就不会刷新。然后,您需要构建一个 JavaScript 函数,从 url 读取主题标签并打开相应的内容。例如。当他们点击链接添加员工时。
接下来,您需要添加一个函数,该函数在加载页面时调用,以读取主题标签并打开相应的部分页面。
Many AJAX applications, such as gmail, use the hashtag (#) part of the url for this purpose. You can change the url using javascript using
document.location
. As long as the part of the url that is before the hashtag remains the same, the page will not refresh. You will then need to build a javascript function that reads the hashtag from the url and opens the appropriate content. For example.And when they click on the link to add employee.
Next you would need to add a function that get called when to page is loaded to read the hashtag and open the appropriate partial page.