【问题标题】:SyntaxError: Unexpected token '{' in jquery.datatablesSyntaxError:jquery.datatables 中出现意外的标记“{”
【发布时间】:2019-10-06 20:17:22
【问题描述】:

我正在尝试在我的代码中使用数据表库,但是在 javascript 控制台中我不断收到 SyntaxError: Unexpected token '{' 错误。

我尝试在网上找到解决方案,发现我的 javascript 可能不正确,但是 javascript 没有显示错误。

我已经在代码中嵌入了这两个库,但是 jQuery.dataTable.min.css 中似乎存在错误。

Image of the error

https://cdn.datatables.net/1.10.20/css/jquery.dataTables.min.css

https://cdn.datatables.net/1.10.20/js/jquery.dataTables.min.js

下面是代码

任何帮助表示赞赏:)

<html>
<head>

         <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
         <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">

             <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
             <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>

</head>


<button id="btn-show-all-children" type="button">Expand All</button>
<button id="btn-hide-all-children" type="button">Collapse All</button>
<table class ="display table" id="myTable" align="center" <table class="display nowrap" width="100%">

<thead>
<tr>
<th> ID </th>
<th> START </th>
<th> END </th>
<th> QUALIFICATION </th>
<th class="none">ID</th>
<th class="none">NAME</th>


</tr>
   </thead>
<?php
   function _isCurl(){
       return function_exists('curl_version');
   }
   if (_iscurl()){
       //curl is enabled
       $url = "http://18.130.253.44/getCourses.php?action=getUnpaid";
       $ch = curl_init();
       curl_setopt($ch, CURLOPT_URL, $url);
       curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
       $output = curl_exec($ch);
       $output = substr($output , strpos($output, "{"));
       $stringreplaced = str_replace(');', '', str_replace('\\', '', $output));


      $decoded = json_decode($stringreplaced, true);

  if (count($decoded['courses'])) {

?>
<tbody>
<?php
        // Open the table


        foreach($decoded['courses'] as $classarray){
        foreach ($classarray['students']as $key1) {
?>
          <tr>
          <td><?php echo $classarray['id'];?> </td>
          <td><?php echo $classarray['start'];?> </td>
          <td><?php echo $classarray['end'];?> </td>
          <td><?php echo $classarray['qualification'];?> </td>
          <td><?php echo $key1['id'];?> </td>
          <td><?php echo $key1['name'];?> </td>


        </tr>
<?php
}
?>

<?php
}
?>
</tbody>
</table>

<?php
}
?>
<?php
}

?>

<script src="https://cdn.datatables.net/1.10.20/css/jquery.dataTables.min.css"></script>
<script src="https://cdn.datatables.net/1.10.20/js/jquery.dataTables.min.js"></script>

<script type="text/javascript">
$(document).ready(function (){
    var table = $('#myTable').DataTable({
        'responsive': true
    });
    // Handle click on "Expand All" button
     $('#btn-show-all-children').on('click', function(){
         // Expand row details
         table.rows(':not(.parent)').nodes().to$().find('td:first-child').trigger('click');
     });

     // Handle click on "Collapse All" button
     $('#btn-hide-all-children').on('click', function(){
         // Collapse row details
         table.rows('.parent').nodes().to$().find('td:first-child').trigger('click');
     });
  });

    </script>
</html>

【问题讨论】:

    标签: javascript php html datatable


    【解决方案1】:

    我们使用标签&lt;link&gt;调用文件css和&lt;script&gt;调用js脚本

    你需要改变这一行

    <script src="https://cdn.datatables.net/1.10.20/css/jquery.dataTables.min.css"></script>
    

    作者:

    <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/dt-1.10.20/datatables.min.css"/>
    

    【讨论】:

      猜你喜欢
      • 2016-08-06
      • 1970-01-01
      • 2016-01-07
      • 2015-10-10
      • 1970-01-01
      • 2022-07-27
      • 1970-01-01
      • 1970-01-01
      • 2020-02-25
      相关资源
      最近更新 更多