A
A
Andrey Angelovich Stock2018-08-22 09:57:37
AJAX
Andrey Angelovich Stock, 2018-08-22 09:57:37

How many elements can be passed in an array via ajax?

Hi all! Help with advice
JS collect JSON array and transfer it with AJAX. I accept and process PHP. the crux of the problem is that PHP only accepts 100 elements, while an array can have 40 or more.
how to be? and what could be the problem (hoster restrictions?)?

var objJSONSave = [];
            $(".my_snippets ").each(function (i, e) {
                console.log('массив для сохранения');
                objJSONSave.push
                ({
                    key: $(e).find(".my_key").text(),
                    search: $(e).find(".my_search").text(),
                    url: $(e).find(".my_url").text(),
                    sitename: $(e).find(".my_sitename").text(),
                    snippet: $(e).find(".my_snippet").text(),
                    poz: $(e).find(".my_poz").val(),
                    neg: $(e).find(".my_neg").val(),
                    type: $(e).find(".my_type").val(),
                    action: $(e).find(".my_action").val(),
                    pos: $(e).find(".my_pos").val()

                });

            });
            objJSONSave.push
            ({
                dateadd: $('#dateadd').val(),
                dateprev: $('#dateprev').val(),
                id: $('#getId').val(),
                link: $('#linkM').val(),
                project: $('#project').val()
            });



            $.ajax({
                type: "POST",
                url: "./tpl/save.php",
                async: true,
                data: {obj: objJSONSave},
                success: function (data) {
                    if (data != '') {
                        alert('all good!');
                        $('#qw').append(data);
                        console.log(objJSONSave);
                    }
                }
            });

$postData = $_POST;

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Anatoly Medvedev, 2018-08-22
@your_uncle

Well, send a json string to the server, it has at least 2000 values. The main thing is to get into the limits on the size of the request body. As a rule, this is about 5 MB (less often 10-20), depending on the server settings. If there are still a lot of values, either raise the limits on the receiving host (easiest) or send in chunks (harder).

D
Dmitry, 2018-08-22
@slo_nik

Good morning.
Look here .
There is a magic line in php.ini: max_input_vars = 1000
Exactly 1000 {value: variable} pairs are passed

V
Vasily Pupkin, 2018-08-22
@HectorPrima

The number of elements is less important than the total size of the POST request.

D
dgrigory, 2018-08-23
@dgrigory

Watch and increase post_max_size , max_input_vars If you are uploading files, then also upload_max_filesize. If the limits are ok, then the problem is in the code

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question