如何在codeigniter中显示json数据

Zia*_* Md 7 javascript php jquery json codeigniter

我的json输出来自codeigniter json_encode.这显示在控制台中,但我无法在html格式的页面上显示它

[
    {"company_name":"Jalalabad Ragib-Rabeya Medical College"},
    {"company_name":"Jalalabad Ragib-Rabeya Medical College"}
]
Run Code Online (Sandbox Code Playgroud)

这是javascript.如何读取这些json数据并显示是一个列表

function getDocCat(catId){     
    var currentValue = catId.value;

      $.ajax({
            type: "POST",
            url: "<?php echo site_url('home/get_com_by_cat') ?>",
            data: { data: currentValue },
            dataType:'json',             
            success: function(result){
            $("load_company_name").html(result);
            },
            error: function() {
                alert('Not OKay');
            }

        });
    }
Run Code Online (Sandbox Code Playgroud)

Oli*_* B. 5

function getDocCat(catId){ 

    var currentValue = catId.value;

      $.ajax({
        type: "POST",
        url: "<?php echo site_url('home/get_com_by_cat') ?>",
        data: { data: currentValue },
        dataType:'json',             
        success: function(result){

            // since the reponse of the sever is like this
            // [
            //     {"company_name":"Jalalabad Ragib-Rabeya Medical College"},
            //     {"company_name":"Jalalabad Ragib-Rabeya Medical College"}
            // ]
            // then you can iterate on the array

            // make sure you have a html element that
            // has an id=load_company_name
            var company = $("#load_company_name");


            // here is a simpe way
            $.each(result, function (i, me) {
                // create a p tag
                // insert it to the 
                // html element with an id of load_company_name
                var p = $('<p/>');
                    // you can access the current iterate element
                    // of the array
                    // me = current iterated object
                    // you can access its property using
                    // me.company_name or me['company_name']
                    p.html(me.company_name);
                    company.append(p);
            });
        },
        error: function() {
            alert('Not OKay');
        }

    });
}
Run Code Online (Sandbox Code Playgroud)