2015-06-29 22:27
浏览 246


iam working on mobile app. in my controller i created a json array and iam trying to display the array values into a list in my html page. i want show the list when html page is automatically loaded.

actually my json array contains 'category_id' $ 'category_name' and iam looking forward to next page when click on the 'category_name'


 <!DOCTYPE html>
 <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>    
 <body id="category_id">
 <div data-role="page" id="catlist"> 
 <div  id="loading" > </div>  
 <div data-role="header" data-position="fixed" data-theme="b">
 <div data-role="main" class="ui-content">

            <ul data-role="listview" data-inset="true" id="category">




 var base_url="http://dev.edfutura.com/nithin/jps/edfuturaMob/";  
 $(document).on("pageinit","#catlist", function() {
 var submitUrl = base_url+"categorylist/get_categorylist"; 
 $("#loading").css("display", "block");
        url: submitUrl,

        dataType: 'json',
        type: 'POST',
        success: function(response)
         //do something pls  
         error: function() 





 function get_categorylist() 

   echo json_encode($cat);  


my json array

 [{"category_id":"1","category_name":"Academic Analysis"},         {"category_id":"2","category_name":"Teaching Analysis"},{"category_id":"3","category_name":"Skill Analysis"}]
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dougu7546 2015-06-29 22:45

    You need to use the response in the $.ajax success function. This response object should be your json object and can therefore easily be accessed via the specified properties category_name and category_id.

        // ...
        success: function(response){
            // do something with the json response! E.g. generate a new list item and append it to the list.
            var categoryList = $('#category');
            var category;
            for(var i = 0, len = response.length; i < len; i++){
                category = response[i];
                categoryList.append($('<li>').attr('id', category.category_id).html(category.category_name));
    解决 无用
    打赏 举报

相关推荐 更多相似问题