search

Home  >  Q&A  >  body text

javascript - ajax request returns 200, how to break json Chinese garbled code?

json file

[{
    id: 2,
    name: '权限控制',
    icon: 'icon-shield',
    type: '0',
    url: '',
    layer: '0',
    pid: 0
}, {
    id: 3,
    name: '用户管理',
    icon: 'icon-shield',
    type: '1',
    url: './snippet/auth/user.html',
    layer: '0,2',
    pid: 2
}, {
    id: 4,
    name: '&测试用例&',
    icon: 'icon-shield',
    type: '1',
    url: './snippet/auth/role.html',
    layer: '0,2',
    pid: 2
}, {
    id: 5,
    name: '权限管理',
    icon: 'icon-shield',
    type: '1',
    url: 'snippet/auth/user.html',
    layer: '0,2',
    pid: 2
}, {
    id: 6,
    name: '品牌供应商管理',
    icon: 'icon-shield',
    type: '1',
    url: 'snippet/auth/user.html',
    layer: '0,2',
    pid: 2
}]

请求的完整代码:
   function menuclick(name, describe) {
    //$('p.page-title h1').empty();
    $('p.page-title h1').html(name + ' <small>' + describe + '</small>');
}
jQuery(document).ready(function() {

    $.ajax({
        type: "get",
        async: false,
        dataType: "json",
        url: "json/leftTree.json",
        beforeSend: function(data) {

        },
        success: function(data) {
            var tree = toTree(data, 0);
            //console.log(tree);
            var str, node, child = [];
            for (var o in tree) {
                (function(node, dom) {
                    if (node.children.length != 0) {
                        str = $('<li><a href="javascript:;"><i class="' + node.icon + '"></i><span class="title">' + node.name + '</span><span class="arrow"></span></a><ul class="sub-menu"></ul></li>');
                        dom.append(str);
                        for (var i in node.children) {
                            arguments.callee(node.children[i], str.find('ul.sub-menu'));
                        }
                    } else {
                        dom.append('<li><a class="ajaxify" href="' + node.url + '" 

onclick="menuclick(\'' + node.name + '\',\'' + node.icon + '\')">' + node.name + '</a></li>');
                        }
                    })(tree[o], $('ul.page-sidebar-menu'));
                }
                Metronic.init(); // init metronic core componets
                Layout.init(); // init layout
                Demo.init(); // init demo features
                QuickSidebar.init(); // init quick sidebar
                Index.init(); // init index page
                Tasks.initDashboardWidget(); // init tash dashboard widget

            },
            error: function(data) {
                console.log("error");
            }
        })
    });
↓↓控制台错误截图↓↓

PHP中文网PHP中文网2778 days ago591

reply all(2)I'll reply

  • 滿天的星座

    滿天的星座2017-05-19 10:48:02

    Set the charset encoding on the server side,

    header("Content-type:text/html;charset=utf-8");

    reply
    0
  • 迷茫

    迷茫2017-05-19 10:48:02

    Is the server not specifying the encoding methodutf-8

    reply
    0
  • Cancelreply