1

I am making use of .post() quite extensively in my CMS application. The example of working code below passes 13 (the most in my application) parameters to the processing.php file which works fine.

When the need requires the passing of more parameters I have simply made use of the action form property which also works fine.

However, I have an application where there is a need to pass 38 variables including large strings, but at the same time perform a check on the action file and if the check fails I need to fire off a js confirmation alert to continue or cancel.

I am not quite sure how to fire the js confirmation alert from the processing.php file and how to return to the originating file with the information entered into the form intact should the user cancel.

I do however understand how to accomplish this if I make use of .post().

My Question is:

Are there any limitations in the number of parameters one should send to a processing.php through .post() as written below or is there another approach I should take to handle the above described problem? And if so what would you suggest?

Example of working code

// code element
    $( "#updateDefaultCodeButton" ).click(function(){
        var url = $('#updateDefaultCodeURL').val();     
        var code_font_family = $('#code_font_family').val(); 
        var code_font_color = $('#code_font_color').val();
        var code_font_weight = $('#code_font_weight').val();
        var code_font_size = $('#code_font_size').val();
        var code_bg_color = $('#code_bg_color').val();
        var code_pad_t = $('#code_pad_t').val(); 
        var code_pad_r = $('#code_pad_r').val(); 
        var code_pad_b = $('#code_pad_b').val();
        var code_pad_l = $('#code_pad_l').val(); 
        var code_w_pad_t = $('#code_w_pad_t').val(); 
        var code_w_pad_r = $('#code_w_pad_r').val(); 
        var code_w_pad_b = $('#code_w_pad_b').val();
        var code_w_pad_l = $('#code_w_pad_l').val(); 
        var postit = $.post( url, {
            code_font_family:code_font_family, 
            code_font_color:code_font_color,
            code_font_weight:code_font_weight,
            code_font_size:code_font_size, 
            code_bg_color:code_bg_color,
            code_pad_t:code_pad_t, 
            code_pad_r:code_pad_r, 
            code_pad_b:code_pad_b,
            code_pad_l:code_pad_l,
            code_w_pad_t:code_w_pad_t, 
            code_w_pad_r:code_w_pad_r, 
            code_w_pad_b:code_w_pad_b,
            code_w_pad_l:code_w_pad_l
        });     
        postit.done(function( data ) {window.location.replace("../generator.php?returnto=manage/global-styles-manage.php");});      
    });
petebolduc
  • 1,233
  • 1
  • 13
  • 20
  • 5
    As a side note, you would have better to serialize the FORM instead of construct manually the datas to post: https://api.jquery.com/serialize/ – A. Wolff Jul 07 '15 at 15:55
  • 1
    Agree with @A.Wolff. Or at least lose all the variable declarations and grab the values directly in post data object i.e `{ code_font_family: $('#code_font_family').val(), ... }` – Andy Jul 07 '15 at 15:59
  • @A.Wolff thank you for your input. This answers the question concerning a better way to perform the task... place it in an answer and I'll give you the check – petebolduc Jul 07 '15 at 16:02
  • 2
    @petebolduc @A.Wolff's comment is very good advice, but is definitely not an appropriate answer to your question. Whether you use `.serialize` or not, you're still sending the same amount of data to your server. – Andy Jul 07 '15 at 16:03
  • @Andy thanks for the additional information I can definitely see the benefits in performance... bummer though... got a lot of re-programming to do. – petebolduc Jul 07 '15 at 16:03
  • @Andy... point taken and understood... the amount of data being sent has never been the issue... it is well within the limitations of the php.ini... I had read somewhere on this site a while back that making use of `.post()` as below had parameter limitations... greatly appreciate you valued input – petebolduc Jul 07 '15 at 16:07

2 Answers2

6

The php.ini contains post_max_size and max_input_vars, both of which can affect the amount you can post to a page.

http://php.net/manual/en/ini.core.php#ini.post-max-size http://php.net/manual/en/info.configuration.php#ini.max-input-vars

You can adjust both if you find yourself above the limit (which will generate a warning in the errorlog).

38 variables should be fine though - max_input_vars defaults to 1,000, and post_max_size defaults to 2MB (I think) so your text strings would have to be very big.

Grim...
  • 16,518
  • 7
  • 45
  • 61
  • I do thank you for your input... I appreciate the time you took to both review my question and offer an answer. I voted you up because the answer is both related to and pertinent to post limitations. – petebolduc Jul 07 '15 at 16:19
  • Apologies - I wasn't being sarcastic. I was pointing out that my "input" was talking about "inputs" and that made me smile. – Grim... Jul 07 '15 at 16:20
1

JQuery Ajax itself doesn't have any limits. The request size is limited on the server however trough various configurations which depend on your environment.

Apache:

  • LimitRequestBody, around 2Gb by default, maybe greater for 64bits, check error logs for details.

PHP:

  • post_max_size which is directly related to the POST size
  • upload_max_filesize which may be unrelated, not sure
  • max_input_time, if the POSt takes too long
  • max-input-nesting-level if your data is an array with a lot of sublevels
  • max_execution_time, but quite sure it's not that
  • memory_limit, as you may reach a size exceding the subprocess allowed memory
  • max_input_vars, if your data array has many elements

Taken from: https://stackoverflow.com/a/9691395/2853903

Community
  • 1
  • 1
Mark
  • 5,437
  • 2
  • 19
  • 29