0

I have a big multidimensional array being sent as ajax post. But in some servers, it does not send the data completely a portion at the end of the array is being cut out.

Is there any limitations?

add_action( 'wp_ajax_pgggo_ajax_sorting_loader',  array($this, 'pgggo_ajax_loader_sorting_callback'));
      add_action( 'wp_ajax_nopriv_pgggo_ajax_sorting_loader', array($this, 'pgggo_ajax_loader_sorting_callback') );

$.ajax({
      url: pgggoAjax.ajax_url,
      type: 'POST',
      context: this,
      data: {
        action: 'pgggo_ajax_pagination_loader',
        nonce: pgggoAjax.nonce,
        pgggosettings: pgggoAjax.pgggosettings,
        pgggopage: parseInt($(this).text()),
        pagesortorderaccent: '',
        pagesortorderdecnet: '',
      },
      success: function(response) {

      },
    });
  });

then in the call back I am using

check_ajax_referer( 'pgggo_ajax_loader_nonce', 'nonce' ); if (isset($_POST['pgggosettings'])) { $data_settings = $_POST['pgggosettings']; }else{ $data_settings = ""; }

the array output is bigone..it exceeds the max limit here. Actually its the elementor widget setting that I am passing

$settings        = $this->get_settings_for_display();     
          wp_enqueue_script('pgggo-ajax-jquery');
          wp_localize_script( 'pgggo-ajax-jquery', 'pgggoAjax', array(
            'ajax_url' => admin_url( 'admin-ajax.php' ),
            'nonce' => wp_create_nonce( "pgggo_ajax_loader_nonce" ),
            'pgggosettings' => $settings,
          ) );
5
  • 1
    A large chunk of the code showing what the data being sent contains, how it's triggered, and what kind of API is being used ot make the AJAX call is missing, can you edit your code to include it? I also noticed you're using the old Admin AJAX interface, is there a reason you haven't used the new REST API? You can make AJAX requests to the REST API, just use register_endpoint to create your new REST endpoint/URL to make connections to
    – Tom J Nowell
    Jan 7, 2020 at 14:14
  • @TomJNowell I have added more details. There are some complications when implementing REST API along with elementor widgets. That's why I have not used it
    – user145078
    Jan 7, 2020 at 14:25
  • @TomJNowell I found the solution It's actually because of ` max_input_vars ` parameter
    – user145078
    Jan 7, 2020 at 17:07
  • I tried googling and found plenty of references to pgggo but never found what the accronym stands for or where the action comes from, can you help identify?
    – Tom J Nowell
    Jan 7, 2020 at 18:49
  • @TomJNowell its post grid by geeky green owl
    – user145078
    Jan 7, 2020 at 19:38

1 Answer 1

0

Anwer is yes it does limit. This server parameter max_input_var sets it. You may have to increase it make it work.

php documentation : max_input_var : How many input variables may be accepted (limit is applied to $_GET, $_POST and $_COOKIE superglobal separately). Use of this directive mitigates the possibility of denial of service attacks which use hash collisions. If there are more input variables than specified by this directive, an E_WARNING is issued, and further input variables are truncated from the request.

4
  • 2
    hmmm you might want to encode that parameter as JSON then it'd be only a single parameter and you can json_decode it at the other end without issues or mangling, you can't send JS objects and arrays as is so they need to be converted somehow, hence being split into multiple inputs
    – Tom J Nowell
    Jan 7, 2020 at 17:12
  • @TomJNowell As JSON size and array size will somewhat similar. Will that make a difference?
    – user145078
    Jan 7, 2020 at 17:21
  • 1
    one gives you more control and lets you preserve the data as is during transit, and only uses a single parameter. The other relies on the browser to break it apart into lots of parameters, requiring you to make server level changes to support it
    – Tom J Nowell
    Jan 7, 2020 at 18:47
  • @TomJNowell Oh okay I will try it that way. Thanks for the explanation
    – user145078
    Jan 7, 2020 at 19:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.