有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Ajax导航问题返回按钮

我在JavaSpring框架中有一个基于Ajax的选项卡切换应用程序,我必须处理后退按钮场景。这是通过下面指定代码成功完成的,现在am面对的效果是第一页加载,而不是为特定历史选择的选项卡显示切换跳转。如果有人能帮上忙,那就太感谢了

var innerTab = "";
function navigateAjaxHtmlSetup(target,response){
        if (typeof target == 'undefined') 
        target = "#ajax-container";  
        $(target).html(response);
        $("input[check-with-select]:checked").parent("label").parent("td").nextUntil(":last").find('select').attr('required', 'required');
        $(target).focus();
        $("#ajax-loader").hide();    
}
function pushStateToHistory(){
    var history = window.history;
    var location = window.location.pathname;
    history.pushState({}, "GHFP", location+activeTabs());
}

function anchorAjaxCall(self,url,state){
        $.ajax({
            type: 'GET',
            url: url,
            dataType: "html",
            success: function (response) {
                var target = self.attr('targeto');
                navigateAjaxHtmlSetup(target,response);
                if (state)
                    pushStateToHistory();
//              if(innerTab != ""){
//                  var anchor  = $("a#"+innerTab);
//                  innerTab = "";
//                  anchorAjaxCall(anchor,anchor.attr('href'));
//              }
            }
        });
}

function activeTabs(){
    selectedTabList = $(".tabs-nav a.active");
    var activeURL;
    if (selectedTabList.length > 0){
        activeURL="#";
        selectedTabList.each(function(index,el){
            activeURL +="/"+$(el).attr('id');
        });
    }else{
        activeURL="";
    }   
    return activeURL;
}

function urlAjaxNavigationHandling(hash){
    if (hash.indexOf('/')!=-1)
    {
        var selectedTabList = hash.substring(1,hash.length).split('/');
        var anchor  = $("a#"+selectedTabList[1]);
        anchorAjaxCall(anchor,anchor.attr('href'),false);
        if (selectedTabList.length > 1)
            innerTab = selectedTabList[2];
    }  
}
window.onpopstate = function(e) {
    urlAjaxNavigationHandling(window.location.hash);
};

尽管我的问题与Spring或Java完全无关,但如果有人在谷歌上搜索以实现基于Ajax的应用程序,我只是将它们指定为标记。这可能会对他有所帮助,因为我在Spring框架中找不到对JQuery的任何内置支持,比如Ruby on Rails


共 (1) 个答案

  1. # 1 楼答案

    Spring框架不像Rails,Grails更接近Rails,而是使用Groovy

    解决问题的方法基本上是使用浏览器的历史记录,因为您已经在尝试了。我唯一能想到的是,你应该看看HTML5历史API http://diveintohtml5.info/history.html,也考虑使用一个像已经被路由器支持的http://backbonejs.org/的JS框架。p>