I recommend loading the page you want into a div
<div id='conteudo'>
And a button to trigger the charge 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 mount the new subpage whereas the loaded subject will be part of a main page that will not be reloaded.
The archive subPag.php
should be treated as a page snippet. You should not have the tags <head>
or <body>
, is an excerpt from your original page.
This has its advantages:
- The CSS of the original page affects the subpage,
- The javascript/jquery functions on the original page can also work on the subpage, as long as you have used it
.on
.
I do not recommend loading too much script in the subpage, as it loads the main page and can easily generate conflicts.
There is another possibility with track loading $.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 a set of information via JSON. This information can be processed in the return function of the command $.post
and directed to a div or other page location/element for changing the current page. This all without changing the top page URL.
With these specifications you gave only with ajax
– Erlon Charles
You can even simulate this with the history, but it will probably have unwanted side effects at some point. http://answall.com/a/16799/70
– Bacco
Ever tried to use Ember.js ? May be useful!
– Bruno Casali
As pointed out by @Erloncharles, it seems that Ajax is the case, if there is no concern with history (for the user) and SEO; after all, we do not want to go back to the Flash era, right! Hahaha! You could take a look at Angularjs. I believe it has two useful features in this case: templates and routing.
– Rui Pimentel
Other technical repair (1): is to use POST. So you would have buttons instead of links, and index would process the POST value to define the content. This one works even with JS off. 1. Gambiarra
– Bacco
NULL you have solved the problem?
– Jorge B.
A friend of mine said that he managed to find the solution using Rewrite URL, I will check with him.
– anon
Then it would be nice if you post the solution here if it actually works. But... Rewrite URL? Are you sure?
– Rui Pimentel