Question

I'm currently looking through the Dajax examples on http://www.dajaxproject.com/pagination/ and when I execute the Random Number Example and the Simple Form Example, I could see:

[20/Jul/2012 15:06:37] "POST /dajaxice/couch.randomize/ HTTP/1.1" 200 61

[20/Jul/2012 15:06:38] "POST /dajaxice/couch.updatecombo/ HTTP/1.1" 200 438

These information tells me that the corresponding ajax tasks are being executed. Now I'm trying to do the pagination example, but I don't know how to trigger my ajax, there's no onclick or onchange event and it's supposed to load directly when i serve my page.

When I use a button (onclick event) to invoke my pagination, it worked.

What am I missing here? Thanks.

Was it helpful?

Solution

Are you using the code from the example completely as is, or have you added to it? If you have, posting the code might help. I presume you have one of the required javascript frameworks in place (jQuery, mootools etc) - a Dajax requirement.

have you imported Dajax in your ajax.py? The example doesn't have it, but I believe it's required:

from dajax.core import Dajax

as the example uses Dajax()

There are also some installed apps settings.py requirements for dajaxice and dajax - described in the docs https://github.com/jorgebastida/django-dajaxice/wiki/installation

You might also want to turn on some logging for Dajax - see Dajax installation for an example, and run with debug=True for awhile if you're not already.


Update:

@Nicholas TJ - Your comment about setup & success through alternate call noted. I did notice another question here where there was a problem with the pagination example, regarding how to call the Dajax process from the template.

How do I call Dajax / Dajaxice functions from my Django template

I've been calling Dajax through JS functions, so the template call method is unexplored territory for me. Sounds like you had similar success with your onclick call. Haven't looked into the possibility of deprecated template call procedures - might be an out of date example.

I also notice that the heading for the example 'pagination_page.html' is written as 'paginator_page' - if the heading is used as the template name there'll be obvious problems. I'll give the example a shot when I'm able.

Ok - at the risk of absurdity - new Update . I got a slightly modified example to work after the vanilla example did not.

It requires

from dajax.core import Dajax

in ajax.py, which the example did not have. It also did not work until I used a RequestContext for the base view - a la:

def pagination_example(request):
items = get_pagination_page(1)
return render_to_response('paginator_example.html',{'items':items},context_instance=RequestContext(request))

Then it worked as expected.

OTHER TIPS

The ajax task needs to be invoke be it with onclick buttons, onchange options or with js.

For this dajax pagination example, it needs data to be populated into the HTML Template first using Paginator from Django, once this is done, then you'll have the option to click on 'previous' or 'next' button, which will trigger the dajax tasks.

If your data is empty at the beginning, you won't be seeing the 'previous' and 'next' button at all.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top