Solving php-based array-based js solution .... js asynchronous request php file returns the array echojs_encode ($ list); the array output is: function (data) {alert (data) }{& quot; 1 & quot ;:{ & quot; id & quot;: 54, & quot; neme & quot;: & quot; sdfa & quot;, & quot; 0 & quot;: & quot; pic & php array passing js solution ....
Js asynchronously requests the php file to return the array echo js_encode ($ list );
Array output: function (data) {alert (data )}
{"1": {"id": 54, "neme": "sdfa", "0": "pic", "1": "http: \/localhost \/xin \/index. php? App = home & mod = new & act = newlist "}," 2 ": {" id ": 46," neme ":" sdfa "," 0 ": "pic", "1": "http: \/localhost \/xin \/index. php? App = home & mod = welcome & act = newlist "}," 3 ": {" id ": 56," neme ":" \ u5212 "," 0 ": "pic", "1": "http: \/localhost \/xin \/index. php? App = home & mod = welcome & act = \ u611f \ u5230 "}," 4 ": {" id ": 58," neme ":" sdfa "," 0 ": "pic", "1": "http: \/localhost \/xin \/index. php? App = space & mod = welcome & act = \ u548c "}," 5 ": {" id ": 87," neme ":" \ u7ba1 \ u7406 \ u5458 ", "0": "pic", "1": "http: \/localhost \/xin \/index. php? App = home & mod = come & act = newlist "}," 6 ": {" id ": 54," neme ":" sdfa "," 0 ": "pic", "1": "http: \/localhost \/xin \/index. php? App = home & mod = welcome & act = \ u8c01 \ u7684 "}}
However, when the for loop is output, it is found that it is unordered... the code is as follows.
Function (data ){
Alert (data );
Alert (data. length); // The value 692 is displayed.
For (var I = 0; I Alert (data [I]); // The pop-up is undefined.
}
But I can copy the pop-up array value ..
As follows:
Var data1 = {"1": {"id": 54, "neme": "sdfa", "0": "pic", "1": "http: \/localhost \/xin \/index. php? App = home & mod = new & act = newlist "}," 2 ": {" id ": 46," neme ":" sdfa "," 0 ": "pic", "1": "http: \/localhost \/xin \/index. php? App = home & mod = welcome & act = newlist "}," 3 ": {" id ": 56," neme ":" \ u5212 "," 0 ": "pic", "1": "http: \/localhost \/xin \/index. php? App = home & mod = welcome & act = \ u611f \ u5230 "}," 4 ": {" id ": 58," neme ":" sdfa "," 0 ": "pic", "1": "http: \/localhost \/xin \/index. php? App = space & mod = welcome & act = \ u548c "}," 5 ": {" id ": 87," neme ":" \ u7ba1 \ u7406 \ u5458 ", "0": "pic", "1": "http: \/localhost \/xin \/index. php? App = home & mod = come & act = newlist "}," 6 ": {" id ": 54," neme ":" sdfa "," 0 ": "pic", "1": "http: \/localhost \/xin \/index. php? App = home & mod = welcome & act = \ u8c01 \ u7684 "}}
........................................ ..................
What's going on?
------ Solution --------------------
Php echo js_encode ($ list );
What we get in js is a string. you need to convert it into a js object.
The simplest answer is eval.