How to POST a django form with AJAX & jQuery

原文地址:http://stackoverflow.com/questions/7335780/how-to-post-a-django-form-with-ajax-jquery

html:


view:

 if request.is_ajax() and request.method == "POST":
        form = TestForm(request.POST, instance=test)
        if form.is_valid():
            form.save()
            results[ 'status' ] =True 
            results['msg'] = u'原因'
            return HttpResponse(simplejson.dumps(results), mimetype='application/json')
        else:
            response_data = {"msg":dict(form.errors), "status":"error"}
            return HttpResponse(json.dumps(response_data), mimetype='application/json')


form error显示效果:


你可能感兴趣的:(How to POST a django form with AJAX & jQuery)