[Answer]-How to store tables using jquery ajax django

1👍

Simply define a url and view just as you would regularly.

Urls

from django.conf.urls import patterns, include, url

urlpatterns = patterns('myproject.app.views',
    url(r'^ajaxdisplay/$', 'ajaxView'),
)

Views

def ajaxView(request):
    #...

If you want, you can use json to return variables you may want to return to your client.

from django.utils import simplejson

def ajaxView(request):
    data = {
           'name':request.GET['name'],
            'age':request.GET['age'],
           }
    return HttpResponse(simplejson.dumps(data))

Client

$.ajax({
    type:'GET',
    data:dataString,
    url:'/ajaxdisplay/',
    datatype:'json',         //don't forget to specify datatype
    success:function(data) {
        alert(data.name);
        alert(data.age);
    }
});

Leave a comment