如何将jSON数组值插入到html页面中的表中

时间:2015-06-29 04:42:19

标签: javascript php html

我的html页面nextPage.html。在这里,我尝试将'category-id' $ 'category_name'发布到列表中,但我无法做到。以下是我的代码部分:

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1, maximum-scale=1">
<link rel="stylesheet" href="css/jquery.mobile-1.4.4.min.css" />
<script src="js/jquery-1.11.1.min.js"></script>     
<script src="js/jquery.mobile-1.4.4.min.js"></script>    
<script src="js/nextPage.js"></script>    
<title>Edfutura1</title>
</head>
<body>
    <center>
        <div id="report" data-role="page">
            <div  id="loading" > </div>
            <div data-role="main" class="ui-content">
                <!--    <div data-role="content">    -->
                <form id="nextForm" method="post">
                    <ul data-role="listview" data-inset="true" id="category">
                    </ul>
                    </div>
                <!--<input type="submit" value="get" id="submitButton">    -->
                </form>
            </div>  
        </div>
    </center>
</body>
</html>

这是我的js页nextPage.js

var serviceURL = base_url;  
$(document).on("pageinit","#report", function() {
    $("#loading").css("display", "block");             
    var form = $("#nextForm");
    var  $categorylist= $('#category'); 
    var submitUrl = serviceURL+"categorylist/get_categorylist"; 

    $.ajax({
        url: submitUrl,
        dataType: 'json',
        type: 'POST',
        success: function(response) { 
                alert("ok");
            },
        error: function() {
                alert("error")
             }
    });
});

我的控制器是categorylist.php

public function get_categorylist() 
    {
        $cat=$this->categorylist_model->get_cat(); 
        echo json_encode($cat);
    }

模型是categorylist_model.php

public function get_cat()
    {
        $this->db->select('category_id,category_name');
        $this->db->from('amm_report_category');
        $query = $this->db->get();

        return $query->result_array(); 
    }

0 个答案:

没有答案