使用jquery AJAX功能可以发送到服务器的数据量是否有限制?

发布于 2024-11-09 03:05:44 字数 955 浏览 0 评论 0原文

我正在使用 jquery 提交表单,由于某些奇怪的原因,只有前 5 个变量被发送到 PHP 文件。代码如下:

$("form#alcs_submit").submit(function() {  
    var game_one = $('#game_one').val();
    var game_two = $('#game_two').val();
    var game_three = $('#game_three').val();
    var game_four = $('#game_four').val();
    var game_five = $('#game_five').val();  
    var game_six = $('#game_six').val();
    var game_seven = $('#game_seven').val();

    $.ajax({  
        type: "POST",  
        url: "mlb_alcs_edit.php",  
        data: "game_one="+ game_one +"& game_two="+ game_two +"& game_three="+ game_three +"& game_four="+ game_four +"& game_five="+ game_five +"& game_six="+ game_six +"& game_seven="+ game_seven,
        success: function()
        {   
            alert(game_six);
            $('#bracket').load('mlb_alcs_changed.php?action=saved');
        } 
     });  
    return false;  
});

有什么建议吗?

谢谢,

兰斯

I'm using jquery to submit a form and for some bizarre reason, only the first 5 variables are being sent to the PHP file. The code is as follows:

$("form#alcs_submit").submit(function() {  
    var game_one = $('#game_one').val();
    var game_two = $('#game_two').val();
    var game_three = $('#game_three').val();
    var game_four = $('#game_four').val();
    var game_five = $('#game_five').val();  
    var game_six = $('#game_six').val();
    var game_seven = $('#game_seven').val();

    $.ajax({  
        type: "POST",  
        url: "mlb_alcs_edit.php",  
        data: "game_one="+ game_one +"& game_two="+ game_two +"& game_three="+ game_three +"& game_four="+ game_four +"& game_five="+ game_five +"& game_six="+ game_six +"& game_seven="+ game_seven,
        success: function()
        {   
            alert(game_six);
            $('#bracket').load('mlb_alcs_changed.php?action=saved');
        } 
     });  
    return false;  
});

Any suggestions?

Thanks,

Lance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寂寞笑我太脆弱 2024-11-16 03:05:44

如果其中一个值包含特殊的 URL 字符,那么它可能会破坏您的查询字符串。您应该在将这些值传递到查询字符串之前对其进行 URL 编码,如下所示:

var game_one = encodeURIComponent($('#game_one').val());

此外,删除与符号之前的空格:

"& game_two=" + game_two 应该是 "&game_two= " + game_two

或者,您可以通过传递对象而不是字符串,让 jQuery 将 POST 数据序列化为键/值对:

var gameData = 
{
    game_one = $('#game_one').val(),
    game_two = $('#game_two').val(),
    game_three = $('#game_three').val(),
    game_four = $('#game_four').val(),
    game_five = $('#game_five').val(),  
    game_six = $('#game_six').val(),
    game_seven = $('#game_seven').val()
}

$.ajax({  
    type: "POST",  
    url: "mlb_alcs_edit.php",  
    data: gameData,
    success: function() { ... }
});

If one of the values contains a special URL character, then it can break your querystring. You should URL encode these values before passing them in they querystring, like this:

var game_one = encodeURIComponent($('#game_one').val());

Also, remove the spaces before the ampersands:

"& game_two=" + game_two should be "&game_two=" + game_two

Alternatively, you can let jQuery handle the serialization of your POST data into key/value pairs by passing an object instead of a string:

var gameData = 
{
    game_one = $('#game_one').val(),
    game_two = $('#game_two').val(),
    game_three = $('#game_three').val(),
    game_four = $('#game_four').val(),
    game_five = $('#game_five').val(),  
    game_six = $('#game_six').val(),
    game_seven = $('#game_seven').val()
}

$.ajax({  
    type: "POST",  
    url: "mlb_alcs_edit.php",  
    data: gameData,
    success: function() { ... }
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文