javascript - ajax returns text type, how to deal with it!
给我你的怀抱
给我你的怀抱 2017-07-05 09:55:56
0
6
884

Array
(

[一般检查] => Array
    (
        [0] => 身高
        [1] => 体重
        [2] => 视力
    )

[内科] => Array
    (
        [0] => 主要病史
        [1] => 血压
        [2] => 发育
        [3] => 胸廓
        [4] => 肺部
        [5] => 心界
        [6] => 心音
        [7] => 节律
        [8] => 脾
        [9] => 肾
        [10] => 神经系统
    )

[外科] => Array
    (
        [0] => 主要病史
        [1] => 皮肤
        [2] => 淋巴结
        [3] => 甲状腺
        [4] => 脊柱
        [5] => 四肢
    )
)

This is the returned content. It looks like an array but is actually a string. How to make it really become an array!

Then I want to combine it into this structure and display it on the front end (I have no idea at all, please educate me) ps: The outer layer li displays the key, and the inner layer displays the details corresponding to the key! ~~

                                <ul>
                                    <li>
                                        <ul> 
                                            <li></li>
                                        </ul>
                                    </li>
                                </ul>
给我你的怀抱
给我你的怀抱

reply all(6)
世界只因有你

The backend converts the output content into json format

exit(json_encode($data));

The front end converts json string into array

res = JSON.parse(res);
或
res = eval('['+res+']');//res = eval('('+res+')');
仅有的幸福

It’s a backend problem, either json or xml is used to transmit data. This kind of data cannot be parsed by the frontend.

If json is returned in the background, get the json returned by ajax. There are two ways to parse and get js objects

1、x = JSON.parse(data)
2、x = eval("(" + data + ")");//固定语法,不需要问为什么,嘻嘻

You’re welcome

某草草

JSON.parse(res)

ringa_lee
[
    {
        "一般检查": [
            "身高",
            "体重",
            "视力"
        ]
    },
    {
        "外科": [
            "主要病史",
            "皮肤"
        ]
    }
]

You can use json structure.

For example:

var a = [1,2,3,4];
var b = [5,6,7,8];
var obj = {};
obj['a'] = a;
obj['b'] = b;
伊谢尔伦

Ask him to correct the back-end problem

typecho

It looks a bit like the information from PHPvar_dump. First, confirm the data key json returned by the backend to make the front-end processing simple

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template