AJAX in Django withjQuery
Here's a few examples on how to implement AJAX functionality in a django application, using the jQuery JavaScript library.
Published: July 2009
Note: This article has been reviewed as of 2011 and now applies to Django 1.3 and jQuery 1.5.
Unlike some other web application frameworks, Django (thankfully) doesn't implement, or bundle with any JavaScript library. However, In this article I'll be using jQuery for the sake of simplicity.
A basic example
Let's start out with some very simple code, in the views.py of your application
from django.http import HttpResponse
def xhr_test(request):
if request.is_ajax():
message = "Hello AJAX"
else:
message = "Hello"
return HttpResponse(message)
# Your URL pattern could be as simple as
(r'^xhr_test