How can I solve the problem of passing array js in php?

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.