SyntaxError: неожиданный токен '{' в jquery.datatables - PullRequest
0 голосов
/ 06 октября 2019

Я пытаюсь использовать библиотеку данных в своем коде, но получаю сообщение об ошибке SyntaxError: Unexpected token '{' в консоли javascript.

Я попытался найти решение в Интернете и обнаружил, что мой javascript, возможно, неверен, однако в javascript нет ошибок.

Я встроил эти две библиотеки в код, однако кажется, что в jQuery.dataTable.min.css есть ошибка.

Изображение ошибки

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>

1 Ответ

0 голосов
/ 07 октября 2019

мы используем тег <link> для вызова файла css и <script> для вызова 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"/>
...