Now here is my situation: I’m making a CMS. When links are clicked, i would like the pages to load dynamically using Ajax. The problem in the links!
The only way to change the address in the address bar real-time is to use anchor tags. But PHP doesn’t get the anchor tags, thus I can’t load page content on site load using PHP.
And if i were to load the pages using a query string, the query string couldn’t be updated in the address bar at the click of a link, since that would reload the page.
I suppose Javascript could check the address, save the anchor tag in a cookie and reload the page, but I’d rather not have to go to such lengths.
Does anyone know a solution to this problem?
There was a similar question not so long ago, and I came up with the following solution.
Your urls should point to real pages in order to get it work in for js disabled users. The click handlers should handle ajax requests. Hash should contain the url, and a part like
&ajaxto indicate the type of the request.If the request is from ajax simply send the content. If it is not, wrap the content into header and footer to respond with a full site.
Urls should work with linking to ajax generated hashes and using them as links. The whole idea is basically mimics the kind of behavior you can see on facebook.
Javascript
.htaccess
prepend
append
get_header()
get_footer()