Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery.ajax multiple data retrieval

When I use this code, I only manage to retrieve recaptcha_response_field. If I remove recaptcha_response_field, I retrieve recaptcha_challenge_field. However, I am unable to retrieve the two at the same time. I only managed to send 1 data.

challengeField = $("#recaptcha_challenge_field").val();
responseField = $("#recaptcha_response_field").val();

var html = $.ajax(
    {
        global: false,
        type: "POST",
        async: false,
        dataType: "html",
        data: "recaptcha_response_field=" + responseField + "&recaptcha_challenge_field=" + challengeField,
        url: "../ajax.recaptcha.php"
    }).responseText;

if(html == "success")
{
    $("#captchaStatus").html("Success. Submitting form.");
    return true;
}
else
{
    $("#captchaStatus").html("Your captcha is incorrect. Please try again");
    Recaptcha.reload();
    return false;
}
like image 511
Guillaume P Avatar asked Oct 14 '22 08:10

Guillaume P


1 Answers

you wrote this line data: "recaptcha_response_field=" + responseField + "&recaptcha_challenge_field=" + challengeField, was wrong.

you can try this:

$.ajax({
   type: "POST",
   url: "some.php",
   data: { name: "John", location: "Boston" }
 }).done(function( msg ) {
          alert( "Data Saved: " + msg );
     });

or data: {recaptcha_response_field : responseField , recaptcha_challenge_field :challengeField

thanks, Chintu

like image 137
Chintan Avatar answered Nov 02 '22 09:11

Chintan