[英]Dajaxice form cookie
function create_comment(){
data = $('.comment_form form').serializeObject();
Dajaxice.iwebs.create_comment(Dajax.process,{'content':data.content,'post_id':data.post_id});
return false;}`
In HTML form I use {% csrf_token %}
cookie. 在HTML格式中,我使用
{% csrf_token %}
cookie。 Django wants to use X-CSRFToken
https://docs.djangoproject.com/en/1.2/ref/contrib/csrf/#ajax How can I implement it? Django希望使用
X-CSRFToken
https://docs.djangoproject.com/en/1.2/ref/contrib/csrf/#ajax如何实现?
My ajax.py
我的
ajax.py
@dajaxice_register
def create_comment(request, content, post_id):
dajax = Dajax() /n dajax.alert('foobar') /n return dajax.json()
Dajaxice works correct but not at forms. Dajaxice工作正常,但形式不正确。 The error is "Something goes wrong"
错误是“出了点问题”
dajaxice works fine for me whenever I set {% csrf_token %}. 每当我设置{%csrf_token%}时,dajaxice都可以正常工作。 Try this instead:
尝试以下方法:
data = $('#<form_id>').serializeObject();
Dajaxice.iwebs.create_comment(Dajax.process,{'data':data});
please use firebug and see what error ur getting, 403 may mean csrf token issues while if u get 'Dajaxice Exception', it will be likely because of internal errors 请使用Firebug并查看您遇到的错误,403可能表示csrf令牌问题,而如果您收到“ Dajaxice Exception”,则很可能是由于内部错误
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.