-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); –
仍然没有解决我的问题。 –