');
- errorList.appendTo(form);
- }
- }
- }
- });
- return false;
-});
$(document).ready(function(){
initAutoupdate();
+
+ // Post form data over AJAX
+ var threadId = $('div.thread').children('.post').first().attr('id');;
+
+ var form = $('#form');
+ var options = {
+ success: updateOnPost,
+ url: '/api/add_post/' + threadId + '/',
+ };
+
+ form.ajaxForm(options);
+
+ function updateOnPost(response, statusText, xhr, $form) {
+ var json = $.parseJSON(response);
+ var status = json.status;
+
+ form.children('.form-errors').remove();
+
+ if (status === 'ok') {
+ resetForm(form);
+ updateThread();
+ } else {
+ var errors = json.errors;
+ for (var i = 0; i < errors.length; i++) {
+ var error = errors[i];
+
+ var fieldName = error.field;
+ var error = error.errors;
+
+ var errorList = $('
-
+
+
{% endif %}