数据表中未定义未捕获的参考错误$

时间:2019-02-22 10:10:10

标签: javascript datatable referenceerror

请再次帮助我。因为我是新手。 我的数据表有问题。当我加载Chrome时,它会给我这样的反馈:

error 1

error 2

我尝试添加此代码,但是它也不起作用。我该怎么办?

<script type="text/javascript">

$(document).ready(function(){

siswa.php代码:

<?php
$this->load->view('admin/head.php');
?>
<body>
    <div class="wrapper">
		<div class="col-sm-12">
  			<div class="card">
    			<div class="card-body">
      				<h4 class="card-title">Data Berhasil Dimasukkan</h4>
      				<br>
      				<a class="btn btn-info" href="<?php echo site_url("admin/nav_admin");?>" role="button" float="right">Back To</a>
      				<br>
      				<br>
					<table class="table table-striped" style="width:100%">
        					<thead>
            					<tr>
                					<th style="width:20%">NISN</th>
                					<th style="width:35%">Nama</th>
                					<th style="width:15%">Jenis Kelamin</th>
                					<th style="width:20%">Nilai</th>
                					<th style="width:20%">Jurusan</th>
            					</tr>
        					</thead>
        				<tbody>
							<?php
							if( ! empty($import)){ // Jika data pada database tidak sama dengan empty (alias ada datanya)
								foreach($import as $data){ // Lakukan looping pada variabel siswa dari controller
									echo "<tr>";
									echo "<td>".$data->nisn."</td>";
									echo "<td>".$data->nama."</td>";
									echo "<td>".$data->jenis_kelamin."</td>";
									echo "<td>".$data->nilai_rata."</td>";
									echo "<td>".$data->kode_jurusan."</td>";
									echo "</tr>";
								}
							} else{ // Jika data tidak ada
								echo "<tr><td colspan='4'>Data tidak ada</td></tr>";
							}
							?>
						</tbody>
					</table>
				</div>
			</div>
		</div>
	</div>

<script type="text/javascript"> // uncaught referenceerror $ is not defined in datatable
  $(function(){
    $("table").DataTable();
  });
</script>

这是head.php代码:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">

    <title>Halaman Admin</title>

    <!-- Bootstrap CSS CDN -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" integrity="sha384-9gVQ4dYFwwWSjIDZnLEWnxCjeSWFphJiwGPXr1jddIhOegiu1FwO5qRGvFXOdJZ4" crossorigin="anonymous">
    <!-- Our Custom CSS -->
    <link rel="stylesheet" href="<?php echo base_url('assets/css/stylesidebar.css');?>">

    <!-- Font Awesome JS -->
    <script defer src="https://use.fontawesome.com/releases/v5.0.13/js/solid.js" integrity="sha384-tzzSw1/Vo+0N5UhStP3bvwWPq+uvzCMfrN1fEFe+xBmv1C/AtVX5K0uZtmcHitFZ" crossorigin="anonymous"></script>
    <script defer src="https://use.fontawesome.com/releases/v5.0.13/js/fontawesome.js" integrity="sha384-6OIrr52G08NpOFSZdxxz1xdNSndlD4vdcf/q2myIUVO0VsqaGHJsB0RaBE01VTOY" crossorigin="anonymous"></script>
</head>

1 个答案:

答案 0 :(得分:0)

将您的js代码放入:

jQuery(function($){

});