if you comment middleware csrf this is a risk security problem in your app maybe you need read this part of documentation
https://docs.djangoproject.com/en/1.7/ref/contrib/csrf/#ajax Cheers On Sat, Jan 17, 2015 at 10:44 PM, Hossein Rashnoo <[email protected]> wrote: > I correct my code and it's worked. Thank you guys for your help. > > Ajax Code: > > function checkuser() { > var myObject = new Object(); > myObject.username = $('#username').val(); > myObject.password = $('#password').val(); > $.ajax({ > url: 'http://10.252.84.159/ajaxrecivelogin/', > type: 'POST', > data: JSON.stringify(myObject), > context: this, > dataType: 'json', > success: function (data) { > alert( data.status ); > }, > error: function () > { > alert( "Error" ); > } > });}; > > Django Code: > > def ajaxrecivelogin(request): > import json > import ast > x = ast.literal_eval(request.body) > response_data = {} > response_data['status'] = username > return HttpResponse(json.dumps(response_data), > content_type="application/json") > > *And i comment out django.middleware.csrf.CsrfViewMiddleware in setting* > > On Saturday, January 17, 2015 at 9:16:32 AM UTC+3:30, Hossein Rashnoo > wrote: >> >> I use this code to send a request: >> >> function checkuser() { >> $.ajax({ >> url: 'http://10.252.84.159/ajaxrecivelogin', >> //type: 'POST', >> data: "{'username': 'aa', 'password' : 'bb'}", >> context: this, >> dataType: 'json', >> success: function (data) { >> $("#resp").html("success"); >> }, >> error: function () >> { >> $("#resp").html("error"); >> } >> });}; >> >> And its worked But when i add type:POST part it cause error. >> >> I use this django code to response that request: >> >> def ajaxrecivelogin(request): >> import json >> response_data = {} >> response_data['status'] = '1' >> return HttpResponse(json.dumps(response_data), >> content_type="application/json") >> >> Is it about my django code? >> >> -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/django-users. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/7c7b115e-73f8-4a8b-bc38-8bf2ec2481ae%40googlegroups.com > <https://groups.google.com/d/msgid/django-users/7c7b115e-73f8-4a8b-bc38-8bf2ec2481ae%40googlegroups.com?utm_medium=email&utm_source=footer> > . > > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAM-7rO1ue1JkAA9nyk8P-zdkG-mKq%2BEEB1dtwLC0pazTXnRE4g%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.

