Improved styling
[dylansserver.git] / includes / ajax.js
1 $(document).ready(function() {
2 $('#recaptcha_widget').show();
3 $('.submit').click(function() {
4 if ($('#comment_text').val() != '') {
5 var challenge = Recaptcha.get_challenge();
6 var response = Recaptcha.get_response();
7 var captcha_data = { "challenge" : challenge,
8 "response" : response};
9 $.ajax({
10 type: "GET",
11 url: "/captcha",
12 data: captcha_data,
13 success: function(data) {
14 if (data.split('\n')[0] == 'true') {
15 var name = $("#comment_name").val();
16 var email = $("#comment_email").val();
17 var text = $("#comment_text").val();
18 var comment_data = { "captcha" : "passed",
19 "name" : name,
20 "email" : email,
21 "text" : text};
22 $.ajax({
23 type: "POST",
24 // the url may need to be adjusted for
25 // trailing slashes
26 url: "verify",
27 data: comment_data,
28 success: function() {
29 var new_post = "<h3><a href='mailto:" + email
30 + "'>" + name + "</a></h3>"
31 + text + "<br><br>";
32 $('#comments').prepend(new_post);
33 $('#comment').hide();
34 console.log('posted new comment');
35 }
36 });
37 } else {
38 console.log('reCAPTCHA said you\'re not human.');
39 }
40 },
41 error: function() {
42 console.log('error');
43 },
44 complete: function() {
45 Recaptcha.destroy();
46 }
47 });
48 } else {
49 console.log('but you didn\'t write anything!');
50 }
51 return false;
52 });
53 });