Home >Backend Development >PHP Tutorial >php---ajax passes multidimensional array to the background

php---ajax passes multidimensional array to the background

WBOY
WBOYOriginal
2016-07-25 08:46:201268browse

php---ajax passes multi-dimensional arrays to the background. Friends in need can refer to it.


1 traditional:true

??Online information generally says that if the ajax parameter traditional is set to true, then the array can be converted into a format string, but this still requires string parsing in the background. This method is too troublesome, so I didn’t test it myself.

2 Convert js object (or array) to json

??The main difference between object and array is that one is an object and the other is an array. The object is surrounded by curly brackets {}, and the array is surrounded by square brackets [].
??Conversion method: JSON.stringify(mydata)

  1. $.ajax({
  2. url: 'xxxxxxxxxxxx',
  3. type: 'POST',
  4. dataType: 'text',
  5. data:{
  6. 'rowData':JSON.stringify(mydata)
  7. },
  8. success : function(data){
  9. console.log(data);
  10. },
  11. error: function(){
  12. alert("Error getting data!");
  13. }
  14. });
Copy code

??After passing it to the background, decode json through json_decode(data);. Similarly, you can check whether the decoded data is correct, and you can return the data through ajaxReturn(). For debugging methods, please refer to this article http://blog.csdn.net/freeape/article/details/50072069.

php


Statement:
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