This article analyzes the order of the return data of Ajax requests. Share to everyone for your reference, specific as follows:
When Ajax requests a url,php backend processing, the array is formatted as follows:
Copy Code code as follows:
$a = Array ('-1 ' =>, '-3 ' => 2, ' 0 ' => ' 5 ', '-2 ' => 4);
Then use the Asort function of PHP to sort the array by value in ascending order, as follows:
Copy Code code as follows:
$a = Array (' 3 ' => 2, '-2 ' => 4, ' 0 ' => ' 5 ', '-1 ' => 10);
The return value that the front-end Ajax receives is still unordered.
Possible causes are: Because the key value is a character swap, JS to the data to reorder processing
The processing programme is as follows:
$i = 0;
foreach ($data as $k => $v) {
$tmp [$i] [' data '] = $v;
$tmp [$i] [' key '] = $k;
$i + +;
}
At this point the data is as follows:
{"
rows": [
{
"data": "2",
"key": 0-3
},
{
"data": "4",
"key": -12
},
{
"Data": "5",
"key": 0
},
{
"data": "Ten",
"key":-1
}
]
}
Ajax receive processing, the data is correct.
I hope this article will help you with Ajax programming.