Recaptcha.reload() solves reload problem
[dylansserver.git] / includes / ajax.js
index 2bc9cce..014e1f5 100644 (file)
@@ -15,6 +15,7 @@ $(document).ready(function() {
               var name = $("#comment_name").val();
               var email = $("#comment_email").val();
               var text = $("#comment_text").val();
+                  if (name == '') { name = "anon" }
            var comment_data = { "captcha" : "passed",
                                        "name" : name,
                                 "email" : email,
@@ -26,27 +27,34 @@ $(document).ready(function() {
                         url: "verify",
                         data: comment_data,
                         success: function() {
-                          var new_post = "<h3><a href='mailto:" + email
-                                          + "'>" + name + "</a></h3>"
-                                                          + text + "<br><br>";
+                          if (email != '') {
+                            var new_post = "<h3><a href='mailto:" + email
+                                            + "'>" + name + "</a></h3>"
+                                                            + text + "<br><br>";
+                          } else {
+                            var new_post = "<h3>" + name + "</h3>"
+                                                            + text + "<br><br>";
+                          }
                           $('#comments').prepend(new_post);
                           $('#comment').hide();
                           console.log('posted new comment');
                         }
                   });
                 } else {
-                  console.log('reCAPTCHA said you\'re not human.');
+           var error = "<span style='font-weight:bold;font-family:sans-serif;color:red;margin-top:15px;'>reCAPTCHA said you're not human</span>";
+                  $('#comment').append(error);
                 }
        },
           error: function() {
             console.log('error');
           },  
           complete: function() {
-            Recaptcha.destroy();
+                   Recaptcha.reload();
           }
      }); 
        } else {
-         console.log('but you didn\'t write anything!');
+      var error = "<span style='font-weight:bold;font-family:sans-serif;color:red;margin-top:15px;'>but you didn't write anything!<br></span>";
+         $('#submit').before(error);
        }
        return false;
   });