diff media/js/membermap.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 c515b7401078
children 13d052fbe4f1
line wrap: on
line diff
--- a/media/js/membermap.js	Mon Dec 14 05:07:28 2009 +0000
+++ b/media/js/membermap.js	Thu Dec 17 04:14:16 2009 +0000
@@ -84,13 +84,17 @@
                               alert(address + ' could not be found on Google Maps.');
                               return;
                            }
-                           $.post('/member_map/add/', {
-                              loc : address,
-                              lat : point.lat(),
-                              lon : point.lng(),
-                              msg : $('#id_message').val()
+                           $.ajax({
+                              url: '/member_map/add/', 
+                              type: 'POST',
+                              data: {
+                                 loc : address,
+                                 lat : point.lat(),
+                                 lon : point.lng(),
+                                 msg : $('#id_message').val()
                               },
-                              function(data, textStatus) {
+                              dataType: 'json',
+                              success: function(data, textStatus) {
                                  var wasOnMap = mmap.userOnMap;
                                  if (mmap.userOnMap)
                                  {
@@ -114,7 +118,11 @@
                                  alert(wasOnMap ? "Your location has been updated!" : 
                                        "You've been added to the map!");
                               },
-                              'json');
+                              error: function (xhr, textStatus, ex) {
+                                 alert('Oops, an error occurred. ' + xhr.statusText + ' - ' + 
+                                    xhr.responseText);
+                              }
+                           });
                      });
                   }
                   return false;
@@ -122,7 +130,11 @@
 
                deleteButton.click(function() {
                   deleteButton.attr('disabled', 'disabled').val('Deleting...');
-                  $.post('/member_map/delete/', function(data, textStatus) {
+                  $.ajax({ 
+                     url: '/member_map/delete/', 
+                     type: 'POST',
+                     dataType: 'text',
+                     success: function(data, textStatus) {
                         $('#id_location').val('');
                         $('#id_message').val('');
                         $("#member_map_members option[value='" + mmapUser.userName + "']").remove();
@@ -137,7 +149,11 @@
                         mmap.resizeUserList();
                         alert("You've been removed from the map.");
                      },
-                     'text');
+                     error: function (xhr, textStatus, ex) {
+                        alert('Oops, an error occurred. ' + xhr.statusText + ' - ' + 
+                           xhr.responseText);
+                     }
+                  });
                   return false;
                });