简体   繁体   English

加载不同的页面,同时保留某些div

[英]Load different pages while leaving certains divs behind

I want to know how some web pages move between different PHP pages without reloading the entire page. 我想知道某些网页如何在不同的PHP页面之间移动而不重新加载整个页面。 Here some divs stays the same. 这里有些div保持不变。 If I use AJAX i cannot share the link of the page, so I need to do this. 如果我使用AJAX,则无法共享页面链接,因此我需要这样做。 Thank you. 谢谢。

You have to use AJAX in order to do that. 您必须使用AJAX才能做到这一点。 BUT if you want to be able to share the link or handle reload ou need to build a navigation system using # and some javascript around it. 但是,如果您希望能够共享链接或处理重载,则需要使用#和周围的一些JavaScript构建导航系统。

There is a lot of example for doing that on the web. 在网络上有很多这样做的例子。

https://www.google.nl/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=tutorial%20build%20ajax%20navigation https://www.google.nl/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=tutorial%20build%20ajax%20导航

You could just load a new page and include the same divs of the page : 您可以只加载一个新页面并包含该页面的相同div:

include 'div1.php';

You could use the other answers below and just use ajax but also build a url at the same time so you can navigate back to the same structure of the page. 您可以使用下面的其他答案,并且只使用ajax,但同时还要构建一个url,以便可以导航回页面的相同结构。 clicking the link modifies the url, eg: 单击链接将修改URL,例如:

document.title = document.title + '?div1=true'

Modify the URL without reloading the page 修改URL而无需重新加载页面

and then just does an ajax call to load a new section. 然后只需执行ajax调用来加载新部分。 And on first page load, parse the url to check what divs to load. 并且在第一页加载时,解析网址以检查要加载的div。

you could use iframes: 您可以使用iframe:

<iframe src="/div1.php" id="div1"></iframe>

And clicking a link loads new stuff to a specific iframe. 然后点击链接会将新内容加载到特定的iframe。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM