Get the App
SLTechnology News&Howtos  ›  Development  › 

An example Analysis of the order of data returned by ajax requests

Shulou Source: shulou.com Published: 2022-06-03 14:23:16 11月14日 Update

Editor to share with you the ajax request return data order of the example analysis, I believe that most people do not know much about it, so share this article for your reference, I hope you will learn a lot after reading this article, let's go to know it!

The details are as follows:

After ajax requests a url,php backend for processing, the array is in the following format:

A = array ('- 1percent = > 10,'- 3' = > 2,'0' = >'5','- 2' = > 4)

Then use the asort function of php to sort the array in ascending order by value, as follows:

$a = array ('- 3'= > 2,'- 2'= > 4) 0' = > 5cm,'- 1century = > 10)

The return value received by the front-end ajax is still unordered.

The possible reason is that because the key value is a character exchange, js reorders the data.

The treatment plan is as follows:

$I = 0 tmp foreach ($data as $k = > $v) {$tmp [$I] ['data'] = $v; $tmp [$I] [' key'] = $k; $ifold foreach;}

At this point, the data is as follows:

{"rows": [{"data": "2", "key": 0-3}, {"data": "4", "key":-12}, {"data": "5", "key": 0}, {"data": "10", "key":-1}]}

Ajax receiving and processing, the data is correct.

The above is all the contents of the article "sample Analysis of the order of return data in ajax requests". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Data processing articles examples questions order analysis content array sort not much function front end ascending order reason most character scheme more format Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Redmi Shulou Tech Info Linux Huawei