On Wed, Jul 21, 2010 at 1:37 PM, Juan Hernandez <vladjani...@gmail.com> wrote: > Hey there, > I have been working a lot with request.is_ajax() to handle forms and the > results have been great so fat yet, I have a question about good practices > and best uses for this function. > Lets say that I executed a function that returned True and instead of > sending the boolean to the template, I do something like this: > def ajaxblue(request): > if request.is_ajax(): > message = "<script>alert('Hello AJAX');</script>" > else: > message = "Hello" > return HttpResponse(message) > this is a very simple function but it shows what I'm trying to say. The js > alert renders itself directly to the template. It works perfectly but > somehow I thing that I'm violating DRY or at least, good practices > What do you guys think? > Thanks a lot > Juan >
You should be leaving the js on the client side and instead pass around json (or equivalent). So test request.is_ajax() and then handle your ajax requests by passing HttpResponse(json, mimetype="application/json") -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.