2015-12-17 78 views
1

我對分頁概念有一個休息服務調用。現在在點擊下一個按鈕/圖標的分頁概念中,我可以調用其餘服務,它返回所需的值,但URL沒有更改,我需要更改URL中的頁碼。我的代碼是下一個圖標事件是如下,」更改Ajax調用中的URL問題

function nextPage(currentPage, totalPageCount) { 
      alert(currentPage+ " Begin nextPage Method " + totalPageCount); 
      var nextPage = currentPage+1; 
      var ctx = "${context}"; 
      var url = ctx+"/adtrack/storelist/National/1/"+nextPage; 
      console.log(url); 
      if(nextPage <= totalPageCount) 
       { 
       jQuery.ajax({ 
        url: url, 
        type: "GET", 
        success: function(msg) { 
        alert("Success"); 
        }, 
        error : function(msg) { 
        alert("Fail"); 
        } 
        }); 
       } 
      else{ 
       alert("Unable to perform the action!!!"); 
      } 
      // return true or false, depending on whether you want to allow the `href` property to follow through or not 
     } 

在上面把它傳到了URL和返回值,但我還需要改變當前的URL網址最新。我如何更新網址?

什麼都我打那個URL的URL必須更新的瀏覽器當前的URL

+0

嘗試使用window.location.href = 「_to _your_ URL」; –

回答

1

你或許應該用歷史的API,它允許mainpulating瀏覽器歷史記錄。

function nextPage(currentPage, totalPageCount) { 
      alert(currentPage+ " Begin nextPage Method " + totalPageCount); 
      var nextPage = currentPage+1; 
      var ctx = "${context}"; 
      var url = ctx+"/adtrack/storelist/National/1/"+nextPage; 
      console.log(url); 
      if(nextPage <= totalPageCount) 
       { 
       jQuery.ajax({ 
        url: url, 
        type: "GET", 
        success: function(msg) { 
        alert("Success"); 
        /* History API goes below, replace /testurl with the string you want */ 
        window.history.pushState(null, null, '/testurl'); 
        }, 
        error : function(msg) { 
        alert("Fail"); 
        } 
        }); 
       } 
      else{ 
       alert("Unable to perform the action!!!"); 
      } 
      // return true or false, depending on whether you want to allow the `href` property to follow through or not 
     } 

只要記住一些舊的瀏覽器可能不支持它

http://caniuse.com/#feat=history

歷史上這裏API

https://css-tricks.com/using-the-html5-history-api/

https://developer.mozilla.org/en-US/docs/Web/API/History_API

2

大家好,我的建議是試圖聲明的變量下一頁作爲一個全局變量,因爲只要你打的功能的新值將被分配到下一頁variable.so嘗試也

 var nextPage=0; 

function nextPage(currentPage, totalPageCount) { 
     /......../ 

     nextPage= currentPage+1; 

    /......../ 

}