Link to home
Start Free TrialLog in
Avatar of derrida
derrida

asked on

ajax pagination with fall back?

Hi
there are a lot of ajax pagination around the web but none i see degrade well, especially none works when javascript is disabled.

anybody knows of an ajax pagination that degrade well?

best regards
Avatar of Ivo Stoykov
Ivo Stoykov
Flag of Bulgaria image

if "javascript is disabled" ajax won't work.
Avatar of derrida
derrida

ASKER

well obviously. but what i want is that when it cannot work since js is disabled i still have a regular php pagination. i am ajaxifying a crud and i take care that it wrks well even if js is disabled . the only issue i have left is the pagination.
Avatar of Gurvinder Pal Singh
It can be done this
-- you need to make the code work by php pagination by default.
-- then in case javascript will be enabled, you can convert the page to do ajax pagination at the body onload event
Easy enough.
Made your pagination buttons to be links to php pagination code.
Also, on your javascript code control the onClick event of those links.

When javascript is enabled the js listener you had will take control of the execution and made the ajax pagination (remember to stop the event bubbling to avoid links to continue).
When javascript is disabled the listender simply won't exist and the link will be followed normally.
Avatar of derrida

ASKER

hi gurvinder372 and Bardobrave

since i`m a php guy i already have php pagination, the thing is i have no idea how to implement both your ideas, which sound good.

can any one give an axample on how to do that?

best regards
Let's try a brief sketch, suposing you use jQuery (one of the most useful javascript frameworks to the date):

Include a .js file into your page with this code:

$(document).ready(function() {
    $(".yourPaginationLinksClass").click(function() {      //this will control the click event on each link
        yourAjaxPaginationCall($(this).html());                 /* you just call your pagination ajax function with
        return false;                                                           the clicked's page number */
    };                                                                                
});

I'm not very sure right now, but I think you need the "return false" to avoid the link to be followed once clicked.

I hope you can make some tests with this brief example. Comment here if you face any problem and we'll try to guide you.

If you need info into using jQuery you can check www.jquery.com, you can use raw javascript, of course, but it's more complex to develop this example.
Avatar of derrida

ASKER

hi
its not the first time i`m using jquery but i`m less comfortable with javascript .

the thing i need help with is exactly the yourAjaxPaginationCall($(this).html());

i realize i should disable the regular click of my pagination (since it takes to another page). so i have my regular php pagination and i disable its regular click, but how to make the ajax pagination is exacly what i have no idea what to do.

hope my english is clear enogh:)

best regards
ASKER CERTIFIED SOLUTION
Avatar of Bardobrave
Bardobrave
Flag of Spain image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of derrida

ASKER

sorry i just forgot all about that question