I recommend loading the page you want within a div
<div id='conteudo'>
And a button to trigger the load event:
<div id='newConteudo'>
With the help of jquery:
$('#newConteudo').on('click', function(){
$('#conteudo').load('subPag.php')
});
In this case the file subPag.php
will have the function to mount the new subpage considering that the loaded subject will be part of a main page that will not be reloaded.
The subPag.php
file should be treated as a single page snippet. You should not have the tags <head>
or <body>
, it's an excerpt from your original page.
This has its advantages:
- The CSS of the original page affects the subpage,
- The javascript / jquery functions of the original page can also work on the subpage as long as you have used
.on
.
I do not recommend uploading too much script on the subpage as it loads the main page and can easily cause conflicts.
There is yet another possibility with the load via $.post
. In this option you use a button / link to activate the function, which in turn can send some data or even form fields to a PHP file. this PHP file, in turn, processes the data and returns via JSON a set of information. This information can be processed in the return function of the $.post
command and directed to a div or other place / page element to change the current page. All this without changing the top page URL.