开发者

jquery.ajax multiple data retrieval

开发者 https://www.devze.com 2022-12-24 02:25 出处:网络
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 sa

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 incorre开发者_运维技巧ct. Please try again");
    Recaptcha.reload();
    return false;
}


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(),
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号