jquery.ajax多重数据检索

时间:2010-03-23 17:09:50

标签: javascript php jquery ajax

当我使用此代码时,我只设法检索recaptcha_response_field。如果我删除recaptcha_response_field,我会检索recaptcha_challenge_field。但是,我无法同时检索这两个。 我只设法发送了1个数据。

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

4 个答案:

答案 0 :(得分:2)

你写了这句话data: "recaptcha_response_field=" + responseField + "&recaptcha_challenge_field=" + challengeField,错了。

你可以试试这个:

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

或           data: {recaptcha_response_field : responseField , recaptcha_challenge_field :challengeField

感谢, Chintu

答案 1 :(得分:1)

尝试

data: {
    recaptcha_response_field: responseField,
    recaptcha_challenge_field: challengeField
}

...

您的意思是$_POST["recaptcha_response_field"]$_POST["recaptcha_challenge_field"]并非都设置在“{1}}内部”。

这是不可能的Firebug的Net-Tab显示请求正常。

您是否检查过服务器日志(暂时启用后期数据记录)

答案 2 :(得分:1)

Maby是这样的?

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

答案 3 :(得分:0)

您可以尝试这样

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