search

Home  >  Q&A  >  body text

javascript - ajax returns text type, how to deal with it!

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>
给我你的怀抱给我你的怀抱2793 days ago914

reply all(6)I'll reply

  • 世界只因有你

    世界只因有你2017-07-05 09:57:56

    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+')');

    reply
    0
  • 仅有的幸福

    仅有的幸福2017-07-05 09:57:56

    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

    reply
    0
  • 某草草

    某草草2017-07-05 09:57:56

    JSON.parse(res)

    reply
    0
  • ringa_lee

    ringa_lee2017-07-05 09:57:56

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

    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;

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-07-05 09:57:56

    Ask him to correct the back-end problem

    reply
    0
  • typecho

    typecho2017-07-05 09:57:56

    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

    reply
    0
  • Cancelreply