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;
}

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


Try

data: {
    recaptcha_response_field: responseField,
    recaptcha_challenge_field: challengeField
}

??

What do you mean that $_POST["recaptcha_response_field"] and $_POST["recaptcha_challenge_field"] are not both set "inside" ajax.recaptcha.php.

That's impossible Firebug's Net-Tab shows that the request just works fine.

Did you check your server logs (enable post data logging temporarily )


Maby something like this?

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

/* Debug */ alert ("Going to send channengeField with value '" + challengeField + "', and responseField with '" + resonseField + "'");

$.post ("../ajax.recaptcha.php", { 
        recaptcha_response_field:   responseField, 
        recaptcha_challenge_field:  challengeField 
    },
    function(data) 
    {
        /* Debug */ alert ("Data Recieved: " + data);

        if (data == "success")
        {
            $("#captchaStatus").html("Success. Submitting form.");

            return true; 
        }
        else
        {
            $("#captchaStatus").html("Your captcha is incorrect. Please try again"); 
            Recaptcha.reload(); 

            return false; 
        }
    });

You can try like this

  data: "recaptcha_response_field=" + $("#recaptcha_challenge_field").val() + "&recaptcha_challenge_field=" + ("#recaptcha_response_field").val(),

Need Your Help

If the path of a file has space in between the uri cannot fetch the file in the path

path uri

The message box crops up could not find part of the path of the file"file path" when i try to open a file that has space in its file path. I have used LocalPath instead of AbsolutePath and it works...

Need help optimizing C++

c++ optimization collision-detection game-physics

I have programmed a simple top-down car driving game that resembles the first GTA, on the GameBoyAdvance. I have used only vector graphics for doing so, and the GBA doesn't handle it very well; bas...