PDA

View Full Version : AJAX Pagination help



feeleash
08-25-2012, 10:27 AM
http://www.dynamicdrive.com/dynamicindex17/ajaxpaginate/index.htm

Hello fellow programmers.

I wanted to ask how is it possible to load an external html page which has the ajax pagination system but make it load on page 2 instead of 0...

I saw this code which explains how to load another page when you are already in ajax pagination, but what about external pages?

Selecting a page dynamically

You can explicitly select a page within the paginated content to jump to anywhere on your page or inside your scripts by calling the method:


bookvarinstance.selectpage(page_number)

Where "page_number" is an integer designating the desired page number to load (0=1st page, 1=2nd page etc). The following link selects the 3rd page of the paginated content instance with variable reference "comments":


<a href="javascript:comments.selectpage(2)">Jump to Page 3</a>

jscheuer1
08-26-2012, 01:25 AM
I'm not sure what you're asking. But if you mean to ask how can I link to my AJAX Pagination page from another page and have it display a specific page, then put this code at the end of your page as shown, just before the closing </body> tag:


<script type="text/javascript">
/* <![CDATA[ */
(function(instance){
function getQval(n) {
if(typeof n !== 'string'){
return null;
}
var r = new RegExp('[?&;]' + n + '=([^&;#]*)'), m = location.search;
return (m = r.exec(m))? unescape(m[1]) : null;
}
var book = getQval('book');
if(book && (book = window[book]) && typeof book === 'object' && book.pages){
try{instance.refresh(book);} catch(e){}
}
var page = getQval('page');
if(page){
page = --page;
if(!isNaN(page)){
try{instance.selectpage(page);} catch(e){}
}
}
})(mybookinstance);
/* ]]> */
</body>
</html>

Just make sure that the mybookinstance in the above is the name of the variable for your AJAX Pagination instance.

Now, say your page with the AJAX Pagination script on it is called myajax.htm. You can have a link on another page to it like so:


<a href="myajax.htm?page=2">Open 2nd Page on myajax.htm</a>

If you have other "books", you can select them in a similar fashion:


<a href="myajax.htm?page=11&book=bookcombo">Open 11th Page of bookcombo on myajax.htm</a>

Be aware that unlike the on page links (javascript:mybookinstance.selectpage(1)) where the number is 0 based, with this method the 0 does nothing, 1 is the first page, 2 is the second, etc.

feeleash
08-30-2012, 07:21 AM
Yes this was exactly what i was looking for!

THANK YOU