首页 > 解决方案 > 通过 php 加载数据未捕获的 ReferenceError

问题描述

我正在尝试使用 php 文件从数据库加载数据我已经设置了我的 html 页面,如下所示,但是当我运行它时,我收到控制台错误“未捕获的 ReferenceError:$ 未在 tabulatortest.html:38 中定义。

我在网上找到了一个关于如何引用 php 文件的示例,我用它来创建我的 html 和 php 文件。

谁能让我知道我哪里出错了,为什么我会出错?

谢谢我。

<script type="text/javascript">
var table = new Tabulator("#tabulator-example", {
  layout: "fitColumns",
  responsiveLayout: "hide",
  tooltips: true,
  addRowPos: "top",
  history: true,
  pagination: "local",
  paginationSize: 10,
  movableColumns: true,
  resizableRows: true,
  initialSort: [{
    column: "subsystem",
    dir: "asc"
  }, ],
  columns: [{
      title: "Subsystem",
      field: "subsystem",
      minWidth: 20
    },
    {
      title: "Doc Number",
      field: "docNumber",
      minWidth: 20
    },
    {
      title: "Description",
      field: "docDescription",
      minWidth: 20
    },
    {
      title: "Discipline",
      field: "Discipline",
      minWidth: 20
    },
    {
      title: "Tag Number",
      field: "tagNumber",
      minWidth: 10
    },
  ],
});



// table.setData(tabledata);
$("#tabulator-example").tabulator("setData", "setData.php");

标签: tabulator

解决方案


出于某种原因,您似乎在代码中使用了旧的 jQuery 方法:

$("#tabulator-example").tabulator("setData", "setData.php");

您应该改为使用以下内容来设置表中的数据:

table.setData("setData.php");

如果您希望在加载时将数据加载到表中,您可以将 url 直接传递到表定义中的ajaxURL选项中,那么您根本不需要调用setData

var table = new Tabulator("#tabulator-example", {
  layout: "fitColumns",
  ajaxURL:"setData.php",
  ....

查看Ajax 文档以获取有关如何使用此功能的完整信息


推荐阅读