From: Dylan Lloyd Date: Thu, 10 Mar 2011 08:09:56 +0000 (-0500) Subject: Added includes/ajax.php, forgot it earlier X-Git-Url: https://disinclined.org/git/?a=commitdiff_plain;h=409920abbe043085f168136e85344a5d28542163;p=dylansserver.git Added includes/ajax.php, forgot it earlier --- 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; + }); +});