Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jan 2004
    Location
    Des Moines, Iowa
    Posts
    219
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question AJAX - back button

    Alright -

    I'm hot and heavy into programming a fantastic site utilizing primarily AJAX functions to load page content (mostly via onClick's)...

    Anyhow - what I failed to realize is that hitting the BACK button in the browser doesn't do a darn thing for me (as far as going back to the previously loaded page content)...

    This, of course, really sucks..


    My "AJAX" stuff is the following:


    most of my links (and yes I am providing alternative page loading and links for non-js users) are like this: onClick="obtainSettings('/somepage.php?pageID=3&someVar=thisword','theOutputDiv');"

    My question is - using the below - is there some way for me to capture the previous page data and furthermore - if back is pressed - get the previous content in 'theOutputDiv'? If so - could someone either provide an example or lead me to one?
    Code:
    var theresponse = "";
    
    
    function parseSettings(divName){	
    	var thediv = document.getElementById(divName);
    	thediv.innerHTML = theresponse;
    }
    
    function obtainSettings(path,divName){
    	
    	//alert(divName);
    	var therequest = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();   
    	therequest.onreadystatechange = function()
    		{
    	 	 if (therequest.readyState == 4)
    			{
    	 	 	 if (therequest.status == 200)
    				{
    				
    		 	 	 theresponse = therequest.responseText;
    		 	 	// theresponse = eval('(' +therequest.responseText+ ')');
    		 	 	 //alert(theresponse);		 	 	
    		 	 	 	parseSettings(divName,'false');			 	 	 
    				}
    	 	 	 else 	{
    			 	 alert('Error File '+ therequest.statusText);
    				}
    			}
    		}
    	var forceGET = "&n="+ parseInt(Math.random()*999999999);
    	therequest.open("GET", path+forceGET, true);
    	
    	therequest.send(null);
    	
    }
    Rich S. Wyatt
    D3 Web Creations

  • #2
    ess
    ess is offline
    Regular Coder
    Join Date
    Oct 2006
    Location
    United Kingdom
    Posts
    866
    Thanks
    7
    Thanked 30 Times in 29 Posts
    This is one of the problems with using Ajax. However, a lot of developers have come up with different solutions to solve this problem.

    In fact, there are some ready made scripts that you can make use of to take care of page bookmark and back/forward buttons

    Here is a good article that explains problems and solutions to Ajax.

    http://www.onjava.com/pub/a/onjava/2...ck-button.html

    Cheers,
    Ess

  • #3
    Regular Coder
    Join Date
    Jan 2004
    Location
    Des Moines, Iowa
    Posts
    219
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by ess View Post
    This is one of the problems with using Ajax. However, a lot of developers have come up with different solutions to solve this problem.

    In fact, there are some ready made scripts that you can make use of to take care of page bookmark and back/forward buttons

    Here is a good article that explains problems and solutions to Ajax.

    http://www.onjava.com/pub/a/onjava/2...ck-button.html

    Cheers,
    Ess
    I believe this may be what I'm looking for. Much thanks!
    Rich S. Wyatt
    D3 Web Creations


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •