Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

133
Views
Jquery Validate element value from get request

I'm trying to use Jquery validator to validate an captcha based on a GET request.

I've tried to use asynchronous functions to fetch the json response from a GET request to util/Captcha.php?action=validate&encryptedCode=W1tlM1hyNjdVb1JvYw==&inputCode=111111

async function getValidCode()
{
  return await validateCaptcha().then(function (data) { 
    console.log(data);
    return data;
  });
}

    async function validateCaptcha() {
      var encryptedCode = btoa($('#hiddenCaptcha').val());
      var inputCode = $("#captchaInput").val();    
      return $.get(`../../../util/Captcha.php?action=validate&encryptedCode=${encryptedCode}&inputCode=${inputCode}` function (response) {
        var response = JSON.parse(response);
    var isValid = response["validCode"]
        
    return isValid;
      });
    }

I am trying to validate #captchaInput based on it's value, on exit from the input, call getValidCode(), parse the json to return a boolean true or false.

This is the jquery validator.


jQuery.validator.addMethod("isCaptchaValid", async function(value, element, params) {
    var valid = await getValidCode();

    console.log("isvalidtest", JSON.parse(valid)["validCode"]);
    //isvalidtest true
    
    return JSON.parse(valid)["validCode"];
    }, jQuery.validator.format("Incorrect Captcha"));

Thank you for your help! :)

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!