doubi1910 2016-05-16 11:58
浏览 10
已采纳

如何返回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() {
    $('#div1').css("display","none");
    id = $(this).attr("value");
    query = 'ajax.php?id='+id;
    myQuery(query);
    $('#div2').css("display","block");
});

$(".buttonset2").click(function() {
    $('#div2').css("display","none");
    value = $(this).attr("value");
    query = 'ajax.php?id='+id+'&var1='value;
    myQuery(query);
    $('#div3').css("display","block");
});

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);
    xmlHttp.send(); 
}
  • 写回答

1条回答 默认 最新

  • duanlianyun0462 2016-09-09 17:41
    关注

    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;    
        myQuery(url);   
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型