Php 未定义变量ajax

Php 未定义变量ajax,php,jquery,ajax,codeigniter,Php,Jquery,Ajax,Codeigniter,这个问题是一个bug。我不知道这个代码中的问题 我正在使用ajax显示我的表。它说的是未定义的变量:输出 这是我的密码: 主计长账户: function get_accounts() { $accounts=$this->Model_admindly->get_accounts(); $output.= ' <table id="example" class="table table-striped table-bordered" cellspaci

这个问题是一个bug。我不知道这个代码中的问题
我正在使用ajax显示我的表。它说的是未定义的变量:输出
这是我的密码:

主计长账户:

function get_accounts()
{
    $accounts=$this->Model_admindly->get_accounts();
    $output.= '
      <table id="example" class="table table-striped table-bordered" cellspacing="0" width="100%">
              <thead>
                  <tr>
                      <th>ID</th>
                      <th>Email</th>
                      <th>Username</th>
                      <th>Last Logged</th>
                      <th>Last IP</th>
                      <th>Date Reg</th>
                      <th>Status</th>
                      <th>Actions</th>
                  </tr>
              </thead>
              <tfoot>
                  <tr>
                      <th>ID</th>
                      <th>Email</th>
                      <th>Username</th>
                      <th>Last Logged</th>
                      <th>Last IP</th>
                      <th>Date Reg</th>
                      <th>Status</th>
                      <th>Actions</th>
                  </tr>
              </tfoot>
              <tbody>';
    foreach($accounts as $key)
    {
        $output.= '<td>'.$key->id.'</td>
                     <td>'.$key->email.'</td>
                     <td>'.$key->username.'</td>
                     <td>'.$key->date_lastlogged.'</td>
                     <td>'.$key->last_ipaddress.'</td>
                     <td>'.$key->date_registered.'</td>
                     <td>'.$key->status.'</td>
                     <td>'.$key->status.'</td>';
    }
    $output.='</table>';
    echo $output;
}
函数get_accounts()
{
$accounts=$this->Model_adminidly->get_accounts();
$output.='
身份证件
电子邮件
用户名
上次记录
最后一个IP
日期注册
地位
行动
身份证件
电子邮件
用户名
上次记录
最后一个IP
日期注册
地位
行动
';
foreach($key作为$accounts)
{
$output.=''.$key->id.'
“.$key->email”
“.$key->username。”
“.$key->date\u lastlogged”
“.$key->last_ipaddress”
“.$key->date\u注册”
“.$key->状态。”
“.$key->状态。”;
}
$output.='';
echo$输出;
}
要使用ajax显示它,请执行以下操作:

<script>
  $(document).ready(function(){
    function fetch_data()
    {
       $.ajax({
        url:"<?php echo base_url()?>Accounts/get_accounts",
        method:"POST",
        success:function(data)
        {
          $("#live_data").html(data);
        }
       });
    }
    fetch_data();
  });
</script>

$(文档).ready(函数(){
函数fetch_data()
{
$.ajax({
url:“帐户/获取帐户”,
方法:“张贴”,
成功:功能(数据)
{
$(“#实时数据”).html(数据);
}
});
}
获取_数据();
});

在尝试
=
之前,您从未初始化过
$output

基本上你有

$output = $output . 'foo';
              ^---undefined at this point
导致错误的原因。你需要有

$output = ''; // create/initialize
$output .= 'foo'; // use

您正在尝试与尚未定义的变量连接:

$output .= '<table...
$output.='简单:

您正在运行
$output.=“blabla”
甚至在创建变量
$output
之前

首先创建它,然后才能将字符串连接到它

function get_accounts()
{
    $output  = "";
    $accounts=$this->Model_admindly->get_accounts();
    $output.= '
或简单删除其第一个引用上的点:

function get_accounts()
{
    $accounts=$this->Model_admindly->get_accounts();
    $output = '

您没有显示完整的消息,但我怀疑您收到了通知?无论如何,如果你这样做:

$output.= '...
然后说“获取变量
输出
并添加此字符串。”

如果该变量不存在,您会收到一条关于它的通知/警告

您可以从第一次开始这样做:

$output = '....
或者用

$output = '';

您有一个XSS漏洞;可能重复的
$output = '';