Home > php教程 > php手册 > body text

Solution to the truncation of the array when submitting a post request in php ajax

WBOY
Release: 2016-10-22 00:00:06
Original
1475 people have browsed it

1. Scene

When I saved the special product list today, I found that there were more than 2,300 pieces of data on the front end, but the actual server only accepted 166 pieces of data and stored them in the database

2. Solution process

After debugging, it was found that the amount of data was correct when the front-end page submitted the post request, but only 166 items could be received from the server.

At first I thought the post request length exceeded the limit, but after looking at the request content, it was only over 200K, and the post request default supports data transmission within 8M.

So I suspected that it might be caused by the internal configuration of PHP. Later, Baidu searched and found the configuration item max_input_vars. This configuration item was added after PHP 5.3.9 version to prevent hash conflicts.

In this case, change the configuration item, The default is 1000, change it to 10000; after restarting the service, it is found that the amount of data obtained by the server is 1666, which is 10 times the previous one, which is exactly what happened after the configuration item was adjusted. multiple.

However, the amount of data transmitted by the front end is uncertain. Even if max_input_vars is set to 100,000, it may not be enough, so we should find another way.

3. Final solution

1. The front end converts the array into json for transmission, that is, JSON.stringify(goodsList)

2. The server receives and parses $goodsList = json_decode($_POST['goodsList'], true);

3. The test found that the data sent from the front end can be obtained by the server, and the problem was successfully solved

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!