From f6387b9c9e0b5517f6b2914d3b7a87a13828f9b7 Mon Sep 17 00:00:00 2001 From: bensonpaul Date: Wed, 26 Jun 2024 11:15:54 +0530 Subject: [PATCH] Fix syntax error in the github --- static/js/main-new.js | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/static/js/main-new.js b/static/js/main-new.js index 7163220..8e80b97 100644 --- a/static/js/main-new.js +++ b/static/js/main-new.js @@ -259,15 +259,30 @@ $('#contact-submit-live').prop('disabled', 'disabled'); $('#contact-submit').click(function (e) { e.preventDefault(); - var recaptcha_response = $("#g-recaptcha-response").val(); - var secret_key = $("#sitkey").val(); - - var verify_url = 'https://www.google.com/recaptcha/api/siteverify?secret=${secret_key}&response=${recaptcha_response}' - - response = requests.post(verify_url) - result = response.json() + // Get the reCAPTCHA response and secret key values from the input fields +var recaptcha_response = $("#g-recaptcha-response").val(); +var secret_key = $("#sitkey").val(); + +// Construct the URL using template literals for easier variable interpolation +var verify_url = `https://www.google.com/recaptcha/api/siteverify?secret=${secret_key}&response=${recaptcha_response}`; + +// Use Fetch API to make a POST request +fetch(verify_url, { + method: 'POST' +}) +.then(response => response.json()) // Parse the JSON response +.then(result => { + // Handle the result here console.log(result); - return false; +}) +.catch(error => { + // Handle any errors that occur + console.error('Error:', error); +}); + +// Prevent the default form submission +return false; + var recaptcha = $("#g-recaptcha-response").val(); var $errorfooter = $('#errorfooter'); // get the reference of the div if (recaptcha === "") {