title: Fetch Data From Database using AJAX in CodeIgniter
body: <p>This code is not working in codeigniter when we get json array from database. 
  How can we get data from database using ajax </p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
   $(window).on("load",function(){
      $.ajax({
          type:'ajax',
          url:'&lt;?php echo base_url('index.php/user_control/showdata/'); ?&gt;', 
          async:false,
          dataType:'json',
          success:function(data)
          {
  //          console.log(data);
              var html='';
              var i; 
              for(i=0;i&lt;data.length;i++)
              {
                  html+='&lt;tr&gt;'+
                          '&lt;td&gt;'+data[i].uname+'&lt;/td&gt;'+
                          '&lt;td&gt;'+data[i].email+'&lt;/td&gt;'+
                          +'&lt;/tr&gt;'; 
              }
              $(".showid").html(html); 
          },
          error:function(data)
          {
              alert('ajax error'); 
          }
      });
  });
  </code></pre>