我正在开发Google Analytics插件,并且面临基于Ajax的分页问题。由于它是分页,因此将为每个下一个和上一个链接请求数据。 (我解决了;这是打字错误。)
我无法正确更新next和previousLink。
我已附上以下截图和代码。
请求下一个和上一个链接点击的下一个和上一个链接的jQuery代码:
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>**
答案 0 :(得分:1)
代码中的问题是拼写错误。 data.nextlink
不是Feed中的内容。它是data.nextLink
(CAPS&#39; L&#39;)。