Hi, I'm doing very basic AJAX operation using Django 1.3.1.
1) First of all, I copied the AJAX + CSRF snippet (https://
docs.djangoproject.com/en/1.3/ref/contrib/csrf/#ajax) to my *.js file
loded by the every HTML page.
2) HTML defines the subject, email, and message fields, but there's no
form.
3) When the user clicks the submit button, jQuery.post(...) is
triggered.
4) My ajax-view.py that receives the request from AJAX checks whether
three inputs are valid and just sends {'success' : 'True'} json.
At this point, 403 error occurs in Safari and Firefox for some reason
while it works fine in Chrome.
What's the problem with my approach? Thanks.
Here's my views
def sent_mail_view(request):
form = ContactForm(request.POST) # ContactForm extends forms.Model
and Contact is Model.
if form.is_valid():
form.save();
response = simplejson.dumps({'success':'True'})
else:
response = simplejson.dumps({'success':'False'})
return HttpResponse(response,
content_type='application/javascript;
charset=utf-8')
and Ajax post call:
jQuery.post("/stores/sendmail/", emailinfo,
function(response) {
if (response.success == "True") { ... }
}, "json");