how do i use django dajax framework with jquery ajax events
Currently i am implementing the front-end of a djangoproject we have here. and we use Dajax (more precisely the Dajaxice) framework.
i don't know the framework, other than simply calling the server (which other developers here have setup with services that i can call to fetch all data)
it seems though that the dajaxice framework, does not fire the jquery ajax even开发者_如何学Cts (which if you think logically seems just) but i would like it to.
especially the global ajaxComplete event would be usefull in our case. so does anyone knowing dajax know how to modify dajaxice to call some or all of the jquery ajax events?
if this is not possible, does anyone know the equivalent? i need to use some code when ajax calls are complete, so if not with the jquery event binder, i would need another way to trigger if an ajax call was complete.
thanks in advance Sander
Hmm... I just took a (very) quick look at dajaxice and I did not get super warm fuzzies about it being "easy to use." I'll admit to a strong personal bias against systems that make me do a lot of plumbing (e.g. putting in specific 'onclick' events) and that was my reaction to dajax. In particular I hate having to create callbacks unless I really need to.
So my answer is to use the jQuery taconite plugin. It allows you to create a fire-and-forget ajax environment. I've used it on several projects and it makes 99% of AJAX-type situations embarrassingly simple to create.
Since I'm a Django developer I created a class to support the creation of properly formed taconite responses. A sample of the code is on my website. The example in the code is deliberately a little more involved than "Hello, World!" because I wanted to show that you can do multiple things (including firing off arbitrary Javascript) with a single taconite response.
if your are using dajax you can use your own callback function and no 'Dajax.process'. For example in this Dajax normal usage:
Dajaxice.foo.my_ajax_function('Dajax.process');
You can write your own callback, for example:
function my_dajax_callback(data){
Dajax.process(data);
//Other stuff
}
And use it:
Dajaxice.foo.my_ajax_function('my_dajax_callback');
Hope This Helps You
As there is currently no support for ajaxcomplete or other ajax events like jquery has them, I chose to simulate the effect by manually calling a function called myAjaxComplete() from within every callback function.
its not the most clean way, i know that, but we need to wait for new versions of dajax and hope for event support.
精彩评论