ext_157608: (Default)
Simon Law ([identity profile] sfllaw.livejournal.com) wrote in [personal profile] maradydd 2009-05-29 02:11 am (UTC)

In Django, we use various views that spit out partial results, which you would have to write anyway, and use jQuery for the loading and the effects.

For [livejournal.com profile] rik's example of:

<%= link_to_remote "Submit to AJAX",
    :update => "dom_id_that_to_be_updated", 
    :url => { :action => "reload" },
    :complete => visual_effect(:highlight,
        "posts", :duration => 0.5) %>
we'd write, by hand, using jQuery:
<a href="#"
   onclick="$('posts').load('{% url posts.views.partial %}', {}, 
                            function() {
                                $(this).effect('highlight', {}, 3000)
                            })">
    Submit to AJAX
</a>

Granted, that’s a lot more code, but there’s a lot less magic. You can, of course, implement a lot of this magic in template tags. Simple Googling shows that this has already been done, but rather poorly from my point of view.

The Django way should probably look like this:

<a href="#" onclick="{{ posts.ajax.reload|effect:highlight }}">
    Submit to AJAX
</a>
using context variables with proper methods to render the JavaScript and some handy filters to add any effects.


Post a comment in response:

If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

If you are unable to use this captcha for any reason, please contact us by email at support@dreamwidth.org