I have the following test application: http://dev.driz.co.uk/ajax/
You can click download links on other pages using jQuery AJAX, and there are two types: globalTabs and localTabs that load content into different panels. NOTE. Each page is actually a full page, but we use only what we want using the jQuery search method.
To improve this, I use the HTML5 History API (History.js for cross-browser).
The headers and URLs change perfectly, and the history stack is pressed successfully, and when I use the back and forward buttons, the URL and title will go back.
Now the complex part is loaded back into the content from the previous state and the more complex loading of the correct type, for example. global or local ajax. To achieve this, I think I need to pass BOTH data and type into a push state so that it can be reused for popstate ...
Can anyone help point me in the right direction? I have all the first parts of the job, just the case of getting this ajax type transmission for pushState and then reusing it with popstate change.
To improve this, I rewrite it as follows to show my plan for transferring type and data:
NOTE: capitalization history is because I use History.js
var App = { init: function() { $(document).ready(function() { $('.globalTabs li a').live('click', function (e) { e.preventDefault(); App.globalLoad( $(this).attr('href') ); }); $('.localTabs li a').live('click', function (e) { e.preventDefault(); App.localLoad( $(this).attr('href') ); }); }); window.addEventListener('popstate', function(event) { // Load correct content and call correct ajax request... }); }, localLoad: function ( url ) { $.ajax({ url: url, success: function (responseHtml) { $('.localContent').html($(responseHtml).find('#localHtml')); $data = { $(responseHtml).find('#localHtml'), 'local'}; History.pushState($data, $(responseHtml).filter('title').text(), url); } }); }, globalLoad: function ( url ) { $.ajax({ url: url, success: function (responseHtml) { $('.mainContent').html($(responseHtml).find('#globalHtml')); $data = { $(responseHtml).find('#globalHtml'), 'global'}; History.pushState($data, $(responseHtml).filter('title').text(), url); } }); } }; App.init();
UPDATE: To clarify this issue, these are two issues that I am asking for help with.
1.) Get back and forth buttons that work with ajax requests so that they load the correct data back into the content area.
2.) Loading the content into the correct area by passing the content using the pushState method so that it knows if it is a global div or local div request.