开发者

Is there a limit on how much data that can be sent to the server using the jquery AJAX function?

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 s开发者_运维技巧uggestions?

Thanks,

Lance


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() { ... }
});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜