これは私のコードです
<script type="text/javascript">
$(document).ready(function() {
$('#spc-comment-flag-form').submit(function() {
$.ajax({
data: $(this).serialize(),
type: $(this).attr('method'),
url: $(this).attr('action'),
success: function(data) {
if( data['error'] == false) {
var msg = 'We got your flag. Our moderators will now look into it. You may close the window now!';
$('#spc-comment-flag-response').html(msg);
}
else {
$('#spc-comment-flag-response').html(data);
}
},
});
return false;
});
});
</script>
編集
サーバー側では、次のようになります。
@csrf_protect
@login_required
def flag(request, comment_id, next=None):
if not request.is_ajax():
raise Http404
data = {}
if request.method == 'POST':
...
data = simplejson.dumps(data)
return HttpResponse(data, mimetype="application/javascript")
else:
raise Http404
私は基本的にサーバー側の人間で、JS を書く必要はめったにありません。私は "error" を送信しました: エラー メッセージと共にエラーがある場合は true、サーバーにエラーがない場合は "error" : false を送信しました。
上記のコードで条件付きロジックが機能しない理由がわかりません!! 誰でも私がそれを修正するのを助けることができますか?