我把它放在變量已經,但它仍然給了我一個錯誤,它說oTable沒有定義jQuery的數據表未捕獲引用錯誤
<script type="text/javascript">
$(document).ready(function(){
$("#test").click(function(){
$.ajax({
url: "https://jsonplaceholder.typicode.com/posts",
success: function(result) {
var oTable = $("#datatable").DataTable({
processing: true,
data: result,
columns: [
{data: 'id'},
{data: 'title'}
]
});
}
});
});
$("#reload").click(function(){
oTable.DataTable().ajax.reload();
});
});
</script>
這裏未捕獲引用錯誤是我的HTML
<table id="datatable">
<thead>
<tr>
<th>ID</th>
<th>TITLE</th>
</tr>
</thead>
</table>
請幫助我謝謝
otable只是內部的點擊功能範圍..嘗試去除「VAR oTable」的「變種」 –