DataTables: table变量的声明最好放在document.ready()的外面

最好把DataTable变量声明到document.ready()外面来,以使得全局函数可以直接引用它

<script>
	var table;  //在外面声明

	$( document ).ready(function() {
		
		table =	$('#myTable').DataTable({....
                }); 
                ...
        });

        
	function deleteRecord(){	
            $.ajax({  
              ...
               success: function(resp){
                	table.draw(); //这里直接引用table对象,让它重绘
               }
               ...
               });
	    }	
</script>

Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.