セットアップを実行し、dajaxproject.com ですべての例を正常に実行しましたが、より複雑なユース ケースで学んだことを使用すると問題が発生します。フォームからのテキストと共に、いくつかのパラメーターを ajax 関数に渡し、それらのデータを使用してオブジェクトを作成したいと思います。
誰かが私を助けることができれば、それは大歓迎です。
jquery と jquery.ba-serializeobject.min.js を使用しています。
Ajax.py:
@dajaxice_register
def save_comment(req, form, user_username, other_username):
dajax = Dajax()
comment_form = CreateCommentForm(deserialize_form(form))
if comment_form.is_valid():
text = comment_form.cleaned_data['text']
user = User.objects.get(username=user_username)
other_user = User.objects.get(username=other_username)
other_profile = Profile.objects.get(user=other_user)
comment = other_profile.comments.objects.create(owner=user, text=text)
comment.save()
return dajax.json()
JS:
<script type="text/javascript">
function add_comment(){
var user = '{{ person.user.username }}';
var other = '{{ other.user.username }}';
var data = $('#comment_form').serialize(true);
Dajaxice.profiles.save_comment(Dajax.process, {'form': data, 'user_username': user, 'other_username': other });
return false;
}
</script>
HTML:
<div><h4>Post Comment:</h4>
<div id="comment_form_errors"></div>
<form action="" id="comment_form" accept-charset="utf-8" method="post">
{% csrf_token %}
{{ commentform.as_p }}
<p><input class="btn profile-comment-submit" id="submit_profile_comment" onclick="add_comment()" type="submit" alt="register" /></p>
<form>
</div>
Chrome のデバッグ コンソールで表示される唯一のエラーは Dajaxice です。問題が発生しました。
重要な可能性があるものを省略した場合は、お知らせください。
どうもありがとう、