From 493598ca7e9b3bd6de8be6d5a9679ae2373c6a9f Mon Sep 17 00:00:00 2001 From: Alex 'AdUser' Z Date: Sun, 3 Jan 2016 15:23:44 +1000 Subject: [PATCH] * comments: * show error if ajax req failed * use .serialize() instead manual form packing --- public/theme/js/main.js | 16 +++++----------- templates/comments/list.html.ep | 4 +++- templates/comments/new.html.ep | 3 ++- 3 files changed, 10 insertions(+), 13 deletions(-) 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 @@ % } -

<%= l('Add') %>

+
+ <%= l('Add') %> +
diff --git a/templates/comments/new.html.ep b/templates/comments/new.html.ep index fec4802..5c64d47 100644 --- a/templates/comments/new.html.ep +++ b/templates/comments/new.html.ep @@ -1,8 +1,9 @@ % my $pageid = stash('pageid') || '';
+

- +