使用html页面中的id将json数组值显示到列表中

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'

nextPage.html

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


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

        </div>

 </div>                 
 </body>
</center>
 </html>

nextPage.js

 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");
 $.ajax({
        url: submitUrl,

        dataType: 'json',
        type: 'POST',
        success: function(response)
        {
         //do something pls  
         },
         error: function() 
        {
            alert("error");

        }

    });





     });  

categorylist.php

 function get_categorylist() 
 {
   $cat=$this->categorylist_model->get_cat(); 


   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"}]
查看全部
dprh34164
dprh34164
2015/06/29 22:27
  • json
  • php
  • html
  • javascript
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

1个回复