python - Django returns invalid ajax response -


i have ajax call in django template file as:

$(document).ready(function () {     $("button#wdsubmit").click(function(){         $.ajax({             type: "post",             url: "/audit/addwd/",             data: $('form.wddetails').serialize(),             datatype: "json",             success: function(msg){             alert(msg);                alert('added successfully');                 $("#newwd").modal('hide'); //hide popup             },             error: function(msg){                 alert(msg.success);             }         });     }); }); 

form:

class wdform(modelform):     class meta:         model = wdmodel         fields = '__all__' 

and view in django :

def addwd(request):         if request.method == 'post':             updated_request = request.post.copy()             updated_request.update({'updated_by': request.user.username})             form = wdform(updated_request)             if form.is_valid():                 form.save()                 response = simplejson.dumps({'success': true})                 return httpresponse(response, content_type="application/json", mimetype='application/json')             else:                 response = simplejson.dumps({'error': true})                 return httpresponse(response , content_type="application/json") 

whenever make ajax call returns error though have sent success(means form valid , data pushed database).

i tried send response={'success':true} doesn't work.

please me solve issue.

environment details: python verion: 3.4 django :1.7 windows os 8

i doubt on line " response = simplejson.dumps({'success': success}) "

you can try jsonresponse objects.

from django.http import jsonresponse return jsonresponse({'foo':'bar'}) 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -