简体   繁体   English

哪种技术可以在不更改URL的情况下更改页面内容?

[英]What technology allows page content to change without changing the URL?

I have seen this on some survey websites. 我已经在一些调查网站上看到了这一点。 What is the C# code they use on the client side to keep the URL same, but when clicking the "Next" button, the same aspx page is maintained 他们在客户端使用什么C#代码来保持URL不变,但是当单击“下一步”按钮时,将保持相同的aspx

  1. without having any query string; 没有任何查询字符串;
  2. without any change even a character in the url; 网址中的字符都没有任何变化; and
  3. the grid, the data , the content, the questions keep changing? 网格,数据,内容,问题不断变化?

Can anyone give a code-wise example how to achieve this? 谁能举一个明智的例子来实现这一目标?

My main query is how is this done in code-behind to change data of page and maintain same url. 我的主要查询是如何在后台代码中完成此操作以更改页面数据并保持相同的url。

Nothing simpler that a session, maintainted at the server side. 在服务器端维护会话最简单。 Store a "current question number" in session, increment it at each succesfull postback and you have what you ask about. 在会话中存储“当前问题编号”,在每次成功回发时将其递增,您就可以提出要求。

Another possibility - a cookie which contains "current question number". 另一种可能性-包含“当前问题编号”的cookie。

Both cookie and session are invisible in the query string of course. 当然,cookie和会话在查询字符串中都是不可见的。

"change data of page and maintain same url." “更改页面数据并保持相同的URL。” Answer is Server.Transfer . 答案是Server.Transfer This method will preserve url. 此方法将保留网址。

The Next button may submit a form using the HTTP POST method. 下一步按钮可以使用HTTP POST方法提交表单。 The form data may contain the session, question and response data. 表单数据可能包含会话,问题和响应数据。 The site uses that to build a new response. 该网站使用它来构建新的响应。 Unlike a GET, a POST does not incorporate data into the URL. 与GET不同,POST不会将数据合并到URL中。

Developers will typically accomplish this task by using AJAX. 开发人员通常将使用AJAX完成此任务。 The basic premise behind it is that only a certain portion of the page (eg a grid or content area) will make a server call and retrieve the results (using Javascript). 它的基本前提是页面的仅特定部分 (例如网格或内容区域)将进行服务器调用并检索结果(使用Javascript)。 The effect achieved is that there has not been a full post back, which is why you don't see the URL or parameters changing. 实现的效果是没有完整的回发,这就是为什么您看不到URL或参数发生更改的原因。

It is possible to do this using jQuery, pure Javascript, or Microsoft's UpdatePanel . 可以使用jQuery,纯Java 脚本或Microsoft的UpdatePanel进行此操作

oleksii's comment has some good links as well: oleksii的评论也有一些很好的链接:

That's the AJAX magic. 那就是AJAX的魔力。 There are many JQuery plugings for this, for example this one with a live demo . 有许多JQuery的plugings这一点,比如这一个现场演示 You can also program it easily using JQuery Get or Post or any other wrapper that use XmlHttpRequest object. 您也可以使用JQuery GetPost或任何其他使用XmlHttpRequest对象的包装器对其进行轻松编程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我们可以更改页面内容而不更改url吗? - Can we change the content of the page without changing the url? 在不更改url的情况下显示自定义页面 - Getting a custom page to show without changing the url 在Xamarin中浏览页面而不更改页面的全部内容 - Navigating through pages in Xamarin without changing the entire content of the page Blazor 导航:在不更改重新加载页面的情况下更新 URL - Blazor Navigation: Update URL without changing reloading page 页面重定向而不更改URL-Umbraco | C# - Page redirect without changing the URL-Umbraco | C# 如何在不更改 url 的情况下将某人重定向到错误页面 - How to redirect someone to the error page without changing the url 是否可以在不更改请求 Url 的情况下重新加载页面 Url? - Is it possible to reload page Url without change request Url? 我应该使用什么页面图像生成技术? - What page-image generating technology should I use? 修改 URL 允许一些用户看到他们不应该看到的内容 - Modifying the URL allows some users to see content they shouldn't 对于使用XMLHttpRequest更改其内容的页面,合适的事件侦听器是什么? - What is the appropriate event listener for a page that change its content using XMLHttpRequest?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM