2012-07-04 20 views
0

function create_comment(){Dajaxice形式的cookie

data = $('.comment_form form').serializeObject(); 
Dajaxice.iwebs.create_comment(Dajax.process,{'content':data.content,'post_id':data.post_id}); 
return false;}` 

在HTML表單中我使用{% csrf_token %}的cookie。 Django想要使用X-CSRFToken https://docs.djangoproject.com/en/1.2/ref/contrib/csrf/#ajax 我該如何實現它?

ajax.py

@dajaxice_register

def create_comment(request, content, post_id):
dajax = Dajax() /n dajax.alert('foobar') /n return dajax.json()

Dajaxice工作正確的,但不是形式。錯誤是「出現問題」

回答

0

只要我設置{%csrf_token%},dajaxice就能正常工作。 試試這個:

data = $('#<form_id>').serializeObject(); 
Dajaxice.iwebs.create_comment(Dajax.process,{'data':data}); 

,請使用Firebug,看看是什麼錯誤ü[R饒人,403可能意味着CSRF令牌問題,同時如果u得到「Dajaxice異常」,那是因爲內部錯誤

的可能