2012-11-28 55 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/