使用ajax和jquery加载页面的一部分,但在url中显示GET变量
为了向您展示我想做的事情,您只需访问 Gmail。当您点击收件箱时,网址会刷新为 ?tab=mm#inbox,页面中唯一刷新的部分是您的电子邮件所在的大部分部分Google 称之为 div.lm 。这怎么可能?他们是否经常使用缓存,或者他们正在使用我不知道的 JavaScript 命令?
我想做的是,我有一个带有两个不同选项卡的页面。
<div id="navcontainer">
<ul id="navlist">
<li id="active"><a href="#" id="current">Products</a></li>
<li><a id="prreq" onclick="show()" >Requests</a></li>
</ul>
</div>
<div class="container"></div>
当用户继续例如。 cart.php 他们将转到第一个选项卡。当用户单击第二个选项卡时,会触发 js 函数,该函数调用文件 cart.php?rq=r ,结果显示在容器 div 中。 (我知道目前我已经发布了)
function show(){
var prstr= ".container";
var data= {
rq: "r"
};
$.ajax({
type: 'POST',
url: "cart.php",
data: data,
success: function(data1)
{
$(prstr).html(data1);
}
});
}
我想要的是当用户刷新页面时仍然位于 cart.php?rq=r 中,而不必再次单击选项卡。 我将不胜感激任何帮助。如果您需要更多信息,请告诉我 先感谢您。
In order to show you what I want to do you just have to visit gmail. When you click on the inbox, the url refreshes to this ?tab=mm#inbox and the only part of the page that refreshes is the big part where your e-mails are which google calls div.l.m . How is that possible? Are they using cache a lot or they are using a javascript command I'm not aware of?
What I want to do is, I have a page with two different tabs.
<div id="navcontainer">
<ul id="navlist">
<li id="active"><a href="#" id="current">Products</a></li>
<li><a id="prreq" onclick="show()" >Requests</a></li>
</ul>
</div>
<div class="container"></div>
When users go on eg. cart.php they are going to the first tab. When users click on the second tab a js function is triggered which calls the file cart.php?rq=r and the results are shown in the container div. (I know that at the moment I have post)
function show(){
var prstr= ".container";
var data= {
rq: "r"
};
$.ajax({
type: 'POST',
url: "cart.php",
data: data,
success: function(data1)
{
$(prstr).html(data1);
}
});
}
What I want is when the user refreshes the page to still be in the cart.php?rq=r and not having to click on the tab again.
I'd appreciate any help. if you need any more information please let me know
Thank you in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
他们只是通过
location.hash
访问 URL 的hash
部分。当哈希值发生变化时,他们必须有一些逻辑来确定刷新页面的哪一部分。They are simply accessing the
hash
component of the url vialocation.hash
. When the hash changes, they must have some logic that determines which part of the page to refresh.