PDA

View Full Version : Ajax Pagination script



bartejer
03-27-2010, 06:04 PM
1) Script Title: Ajax Pagination script v1.2.2

2) Script URL (on DD):

http://www.dynamicdrive.com/dynamicindex17/ajaxpaginate/

3) Describe problem:I use this script with very long texts which requires me to scroll down in order to get to the bottom of the page.
Is there any way to make the script scroll back to the top of the page every time I click the links at bottom navigation?
Thanks in advance.

jscheuer1
03-27-2010, 08:32 PM
Find this in the ajaxpagination.js file:


ajaxpageclass.loadpage=function(page_request, divId){
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)){
document.getElementById(divId).innerHTML=page_request.responseText
}
}

Using a plain text editor like NotePad, change it to:


ajaxpageclass.loadpage=function(page_request, divId){
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)){
var t = document.getElementById(divId);
if(t.scrollTo){
t.scrollTo(0, 0);
}
if(t.scrollTop){
t.scrollTop = 0;
}
t.innerHTML=page_request.responseText;
}
};

bartejer
03-27-2010, 10:16 PM
Thank you john,I changed the code,unfortunately there's still no change.

jscheuer1
03-28-2010, 03:40 AM
Possibly reversing the order may work:


ajaxpageclass.loadpage=function(page_request, divId){
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)){
var t = document.getElementById(divId);
if(t.scrollTop){
t.scrollTop = 0;
}
if(t.scrollTo){
t.scrollTo(0, 0);
}
t.innerHTML=page_request.responseText;
}
};

However, it's also possible it already worked and you were simply viewing an old cached version, or that you didn't actually make the change to the page you then later tested on, or that there is something peculiar about your layout and/or setup that is preventing this from working, or I may not have understood the situation.

Bottom line, since this didn't work for you, if the above code and/or information doesn't lead you to a solution, all I can do without seeing the page is guess. That's too time consuming.

So, if you want more help:

Please post a link to a page on your site that contains the problematic code so we can check it out.

bartejer
03-29-2010, 05:28 PM
Here's a link to the page which uses the ajax pagination script:
http://www.animequotes.net/aq/Meaningful.php

I transfered the page with the ajax pagination script to a specific folder because it's not ready yet and I can't replace the original one before I finish.

Now about the problem,when you click "2" or "next" for example, the text field will change to page number 2 but you will still remain at the end of the page and you will have to scroll up manually in order to read page 2 from the beginning.
I wanted to know if there is a way that you won't have to scroll up by yourself every time you choose a page.

By the way the page that I sent you the link to is using the second Ajax code you sent me.

Thanks

jscheuer1
03-29-2010, 09:51 PM
I misunderstood the problem. I thought you meant the scroll state of the quote container. Now I think you mean the scroll state of the window. If so, this will do it:


ajaxpageclass.loadpage=function(page_request, divId){
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)){
document.getElementById(divId).innerHTML=page_request.responseText;
if(window.scrollTo){
scrollTo(0, 0);
}
}
}

bartejer
03-30-2010, 12:15 AM
IT WORKS! Thank you so much! :)