Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery codeigniter和JSON_Jquery_Json_Codeigniter_Model_Controller - Fatal编程技术网

Jquery codeigniter和JSON

Jquery codeigniter和JSON,jquery,json,codeigniter,model,controller,Jquery,Json,Codeigniter,Model,Controller,大家好,我有一个问题,它在我的数据库和我的标题中只得到1个值,我想显示同一个表中的内容和用户名 这是我的JSON kode <script type="text/javascript"> $.getJSON( 'ajax/forumThreads', function(data) { alert(data[0].overskrift); alert(data[0].indho

大家好,我有一个问题,它在我的数据库和我的标题中只得到1个值,我想显示同一个表中的内容和用户名

这是我的JSON kode

      <script type="text/javascript">
    $.getJSON(
         'ajax/forumThreads', 
         function(data) {
             alert(data[0].overskrift);
             alert(data[0].indhold);
         }
     );
  </script>

$.getJSON(
“ajax/forumThreads”,
功能(数据){
警报(数据[0]。过度克里夫特);
警报(数据[0].indhold);
}
);
我的控制器

    <?php
class ajax extends Controller
{

 function forumThreads() {

     $this->load->model('ajax_model');
     $data['forum_list'] = $this->ajax_model->forumList();

     if ($data['forum_list'] !== false) {
         echo json_encode($data['forum_list']);
     }
 }

}
试试看

select
方法采用两个参数:第一个参数是作为字符串的选定字段,第二个参数是布尔值,如果设置为false,将防止CI在字段或表名周围使用反勾号。(谢谢@predrag.music)


OT:说到CI的方法,“活动记录”类只不过是一个查询字符串工厂,但它使自己看起来更像一个查询字符串工厂。这是错误的。选择接受2个参数。如果第二个参数为FALSE,则Codeigniter“…将不会尝试用反勾号保护字段或表名…”
    <?php
class ajax_model extends Model
{

 function forumList()
 {
     $this->db->select('overskrift', 'indhold', 'brugernavn', 'dato');
     $this->db->order_by('id', 'desc');
  $this->db->limit(5);
     $forum_list = $this->db->get('forum_traad');

     if($forum_list->num_rows() > 0)
     {
         return $forum_list->result_array();
     } else {
         return false;
     }
 }

}
$this->db->select('overskrift, indhold, brugernavn, dato');