diff --git a/public/theme/js/main.js b/public/theme/js/main.js index 26724e9..aab6783 100644 --- a/public/theme/js/main.js +++ b/public/theme/js/main.js @@ -18,21 +18,15 @@ $(document).ready(function() { $('a#cadd').click(function(e) { e.preventDefault(); $(this).remove(); - $('#comments').load('/comments/new', function() { + $('div#cadd').load('/comments/new', function() { // form submit with ajax $('#comments form').submit(function(e) { e.preventDefault(); - var url = document.createElement('a'); - url.href = window.location; - var text = $('#comments textarea').val(); - $.post('/comments/add', { - 'pageid': escape(url.pathname), - 'text': text, - }, function() { - location.reload(); - }); + $.post('/comments/add', $(this).serialize()) + .done(function(data) { location.reload(); }) + .fail(function(data) { $('#comments #resp').val(data); }); }); // form submit }); // on form load }); // #cadd click - }); // #comments + }); // #comments load }); // document ready diff --git a/templates/comments/list.html.ep b/templates/comments/list.html.ep index 4c66be5..7c4d06d 100644 --- a/templates/comments/list.html.ep +++ b/templates/comments/list.html.ep @@ -13,4 +13,6 @@ % } -
+