2012-11-28 142 views
1

我有一个Ajax基本选项卡切换应用程序在Java Spring框架中,我必须处理后退按钮场景。它通过下面指定的代码成功完成。现在,所面临的效果是首页加载,而不是选项卡切换跳转对于选定的特定历史记录显示。如果有人帮助此问题,这将是非常感谢。Ajax导航发布返回按钮

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); 
}; 

虽然我的问题没有涉及到春季或Java在所有我只是指定这些作为标签,如果有人谷歌围绕实现Ajax应用基地。这可能对他有所帮助,因为我没有在Spring框架中找到任何内置的JQuery支持,因为Ruby on Rails

回答

0

Spring Framework不像Rails,Grails接近Rails,但是使用Groovy。

您的问题的解决方案基本上与浏览器的历史一起工作,因为您已经在尝试。我唯一能想到的就是应该看看HTML5 History API http://diveintohtml5.info/history.html,并且考虑使用已经支持路由器的js框架,如http://backbonejs.org/