From 409920abbe043085f168136e85344a5d28542163 Mon Sep 17 00:00:00 2001 From: Dylan Lloyd Date: Thu, 10 Mar 2011 03:09:56 -0500 Subject: [PATCH] Added includes/ajax.php, forgot it earlier --- includes/ajax.js | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 includes/ajax.js diff --git a/includes/ajax.js b/includes/ajax.js new file mode 100644 index 0000000..50541dc --- /dev/null +++ b/includes/ajax.js @@ -0,0 +1,47 @@ +$(document).ready(function() { + $('.submit').click(function() { + if ($('#comment_text').val() != '') { + var challenge = Recaptcha.get_challenge(); + var response = Recaptcha.get_response(); + var captcha_data = { "challenge" : challenge, + "response" : response}; + $.ajax({ + type: "GET", + url: "/captcha", + data: captcha_data, + success: function(data) { + if (data.split('\n')[0] == 'true') { + var name = $("#comment_name").val(); + var email = $("#comment_email").val(); + var text = $("#comment_text").val(); + var comment_data = { "captcha" : "passed", + "name" : name, + "email" : email, + "text" : text}; + $.ajax({ + type: "POST", + // the url may need to be adjusted for + // trailing slashes + url: "verify", + data: comment_data, + success: function() { + console.log('posted new comment'); + } + }); + } else { + console.log('reCAPTCHA said you\'re not human.'); + } + }, + error: function() { + console.log('error'); + }, + complete: function() { + Recaptcha.destroy(); + } + }); + } else { + console.log('but you didn\'t write anything!'); + } + return false; + }); +}); -- 2.30.2