Mercurial > public > sg101
diff media/js/shoutbox_app.js @ 150:b43e1288ff80
Fix #33; use $.ajax instead of $.post so we can handle errors. Also, for some reason comparing objects in a template doesn't work now. Have to compare id fields.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Thu, 17 Dec 2009 04:14:16 +0000 |
parents | 777451a98f9d |
children |
line wrap: on
line diff
--- a/media/js/shoutbox_app.js Mon Dec 14 05:07:28 2009 +0000 +++ b/media/js/shoutbox_app.js Thu Dec 17 04:14:16 2009 +0000 @@ -11,13 +11,23 @@ if (confirm('Really delete this shout?')) { var id = this.id; if (id.match(/^shout-del-(\d+)/)) { - $.post('/shout/delete/', { id : RegExp.$1 }, function (id) { + $.ajax({ + url: '/shout/delete/', + type: 'POST', + data: { id : RegExp.$1 }, + dataType: 'text', + success: function (id) { var id = '#shout-del-' + id; $(id).parents('tr').fadeOut(1500, function () { $('div.shoutbox-history table tr:visible:even').removeClass('odd'); $('div.shoutbox-history table tr:visible:odd').addClass('odd'); }); - }, 'text'); + }, + error: function (xhr, textStatus, ex) { + alert('Oops, an error occurred. ' + xhr.statusText + ' - ' + + xhr.responseText); + } + }); } } return false; @@ -30,11 +40,21 @@ 'or is not appropriate. ' + 'A moderator will be notified and will review the shout. ' + 'Are you sure you want to flag this shout?')) { - $.post('/shout/flag/', { id : id }, function(response) { - alert(response); - }, 'text'); + $.ajax({ + url: '/shout/flag/', + type: 'POST', + data: { id : id }, + dataType: 'text', + success: function(response) { + alert(response); + }, + error: function (xhr, textStatus, ex) { + alert('Oops, an error occurred. ' + xhr.statusText + ' - ' + + xhr.responseText); + } + }); } } return false; }); - }); +});