Jack Cykor Jack Cykor - 6 months ago 38
jQuery Question

How to go back to a function in jquery

I have some buttons when a user click one of them they update the content of the page through ajax then the buttons are hidden and some new buttons are available for user. The problem is when i hit the back button it doesn't go back to the previous function. I want the user to go back to the previous set of buttons here is my code :

$(".buttonset1").click(function() {
id = $(this).attr("value");
query = 'ajax.php?id='+id;

$(".buttonset2").click(function() {
value = $(this).attr("value");
query = 'ajax.php?id='+id+'&var1='value;

Now div2 is shown to the user.... myQuery function does the ajax query

function myQuery(url) {
if (window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
} else {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
document.getElementById("sql").innerHTML = xmlHttp.responseText;
xmlHttp.open('GET', url, true);


Solved it was pretty simple

 History.Adapter.bind(window,'statechange',function(){ // Note: We are using statechange instead of popstate
    var State = History.getState(); // Note: We are using History.getState() instead of event.state 
    var url = State.url;