jQuery 如何在 Ajax 加载数据表中使用回调函数?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16475668/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to use a callback function in the Ajax Loaded Datatable?
提问by sushil bharwani
$(document).ready(function() {
$('#example').dataTable( {
"bProcessing": true,
"sAjaxSource": '../ajax/sources/arrays.txt'
} );
} );
In above example when sAjaxSource loads the data into datatable i want to have a callback function which is called after the data load, What is the proper way of doing it.
在上面的示例中,当 sAjaxSource 将数据加载到数据表中时,我想要一个在数据加载后调用的回调函数,正确的做法是什么。
The above given solution does not answers my problem. I do not want to do anything with the data from the datatable, I just want to wait till the data has loaded and then use that data to update another div on my DOM.
上面给出的解决方案没有回答我的问题。我不想对数据表中的数据做任何事情,我只想等到数据加载完毕,然后使用该数据更新我的 DOM 上的另一个 div。
回答by Kailash Yadav
Here is the example for dataloaded from server callback function. You can modify the data as well using the same function.
这是从服务器回调函数加载数据的示例。您也可以使用相同的功能修改数据。
$(document).ready( function() {
$('#example').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "xhr.php",
"fnServerData": function ( sSource, aoData, fnCallback, oSettings ) {
oSettings.jqXHR = $.ajax( {
"dataType": 'json',
"type": "POST",
"url": sSource,
"data": aoData,
"success": fnCallback
} );
}
} );
} );
Call back functions here: Datatable Callback functions
回调函数在这里:数据表回调函数