-1
我正在開發Google Analytics插件,並面臨基於Ajax的分頁問題。數據將被請求每一個下一個和上一個鏈接,因爲它是分頁。 (我解決了它,這是一個輸入錯誤。)無法使用jQuery更新網址
我無法獲得正確更新和previousLink。
我附上了下面的屏幕截圖和代碼。
jQuery代碼請求下一併previousLink爲下一個和以前的鏈接點擊:當頁面加載新鮮
jQuery('document').ready(function(){
jQuery('.next-page,.prev-page').click(
function(event){
event.preventDefault();
url = jQuery(this).attr('href');
console.log(url);
jQuery.ajax({
url: url,
context: document.body
}).done(function(data){
console.log(data.previousLink);
console.log(data.nextLink);// https://www.googleapis.com/analytics/v3/data/ga?ids=ga:85914642&dimensions=ga:pagePath,ga:date&metrics=ga:pageviews,ga:uniquePageviews,ga:sessionDuration,ga:bounceRate,ga:exits&sort=ga:pageViews&filters=ga:pageViews%3C%3D10&start-date=7daysAgo&end-date=today&start-index=1&max-results=10
if(data.previousLink != 'undefined' && accessToken != 'undefined'){
// jQuery('.prev-page').prop("href", data.previousLink + '&access_token=' + accessToken);
jQuery('.prev-page').attr("href", data.previousLink + '&access_token=' + accessToken);//for first nextlink click and then previous link click http://localhost/analytica-test/wp-admin/undefined&access_token=ya29.RwLlLWsZlGzURfJiOYwkefk_Kpu0XIpKj0XoPHi5_n8nbSdmguInQgLRxXo3Ld0YjdvXeQ
//jQuery('.prev-page').href = data.previousLink + '&access_token=' + accessToken ;
}
if(data.nextlink != 'undefined' && accessToken != 'undefined'){
// jQuery('.next-page').prop("href", data.nextLink + '&access_token=' + accessToken);//after first time nextlink is clicked http://localhost/analytica-test/wp-admin/undefined&access_token=ya29.RwJ0guP0f2kr17Jyz8Dqcg0sM7RN4IQpyAehMpniRh8tspbNaIjcUvb2tzPI9ZD8zdG5DQ
jQuery('.next-page').attr("href", data.nextLink + '&access_token=' + accessToken);// after first time nextlink is clicked http://localhost/analytica-test/wp-admin/undefined&access_token=ya29.RwLlLWsZlGzURfJiOYwkefk_Kpu0XIpKj0XoPHi5_n8nbSdmguInQgLRxXo3Ld0YjdvXeQ
//jQuery('.next-page').href = data.nextLink + '&access_token=' + accessToken ;
}
});
});
});
HTML
**<div class="tablenav-pages"><span class="displaying-num">445 items</span>
<span class="pagination-links"><span class="tablenav-pages-navspan" aria-hidden="true">«</span>
<a class="prev-page" href="&access_token=ya29.RwIyTJjW7Bi0l-SLAQozJF6TT_-ynCOX1dzvMyOEdafY3NNp1CcO18codDhmoJYiucVCfw"><span class="screen-reader-text">Previous page</span><span class="tablenav-pages-navspan" aria-hidden="true">‹</span></a>
<span class="screen-reader-text">Current Page</span><span id="table-paging" class="paging-input">1 of <span class="total-pages">45</span></span>
<a class="next-page" href="https://www.googleapis.com/analytics/v3/data/ga?ids=ga:85914642&dimensions=ga:pagePath,ga:date&metrics=ga:pageviews,ga:uniquePageviews,ga:sessionDuration,ga:bounceRate,ga:exits&sort=ga:pageViews&filters=ga:pageViews%3C%3D10&start-date=7daysAgo&end-date=today&start-index=11&max-results=10&access_token=ya29.RwIyTJjW7Bi0l-SLAQozJF6TT_-ynCOX1dzvMyOEdafY3NNp1CcO18codDhmoJYiucVCfw"><span class="screen-reader-text">Next page</span><span class="tablenav-pages-navspan" aria-hidden="true">›</span></a>
<span class="tablenav-pages-navspan" aria-hidden="true">»</span></span></div>**
你在哪一行注意到data.nextLink中的'l'? –
無論你引用data.nextlink,使用小'l'。它應該是資本。 (e-g) jQuery('。next-page')。prop(「href」,data.nextlink +'&access_token ='+ accessToken); –
仍然沒有解決我的問題。 –