0

我正在使用 POST 请求将数据发送到服务器,但我想发送这样的经典请求是否更好:

$.post(
    "<?php echo Settings\Path\URL::$ajax?>/ajaxValidator.php",
    {
                      item : "Captcha",
        recaptchaChallenge : Recaptcha.get_challenge(),
         recaptchaResponse : Recaptcha.get_response()
    },
    function(result){
        if(result == "true"){
            signup();
        } else {
            $("#signupRecaptchaError").show();
            recaptchaCreate();
        }
    }
);

或者如果最好使用 JSON 的 POST 请求发送数据,如下所示:

var data = {
                      item : "Captcha",
        recaptchaChallenge : Recaptcha.get_challenge(),
         recaptchaResponse : Recaptcha.get_response()
}

$.post(
    "<?php echo Settings\Path\URL::$ajax?>/ajaxValidator.php",
    data,
    function(result){
        if(result == "true"){
            signup();
        } else {
            $("#signupRecaptchaError").show();
            recaptchaCreate();
        }
    }
);

如果有什么不同,你能告诉它是什么吗?

4

2 回答 2

1

没有区别。您只更改了客户端收集数据的方式。请求完全相同。

哪种收集数据的方法更好取决于框架的整体结构。

Looking at your code I can identify some other issues that need addressing before you can start worrying about large architectural questions like this. So my recommendation is: it doesn't matter for now, until you can come up with with a clear reason why one is better than the other.

于 2013-02-28T15:48:06.873 回答
0

没有任何区别,但我个人更喜欢后者。将参数抽象为您提供更大的灵活性。如果需要,它允许您在运行时交换值。

于 2013-02-28T15:47:57.113 回答