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