[英]Is it possible to POST datatable as AJAX data to a server?
I'm using PHP and CodeIgniter. 我正在使用PHP和CodeIgniter。 I add some dummy data to datatable below, and I want to save this data in a database.
我将一些虚拟数据添加到下面的数据表中,并且我想将此数据保存在数据库中。 Is it possible to POST this datatable to a server as AJAX data?
是否可以将此数据表作为AJAX数据发布到服务器?
If yes, how can I fetch it? 如果是,我该如何获取? What is the best way ?
什么是最好的方法 ?
$(document).ready(function() {
var t = $('#example').DataTable();
var counter = 1;
//// addrow
$('#addRow').on('click', function() {
t.row.add([
counter + '.1',
counter + '.2',
counter + '.3',
counter + '.4',
counter + '.5'
]).draw(false);
counter++;
});
});
AJAX: AJAX:
$.ajax({
url: base_url + 'personel/createPersonel',
type: 'post',
data: data // ??
dataType: 'json',
success: function(response) {
...
Thanks. 谢谢。
Isolate the array into a variable that can be both sent to server and added to table 将数组隔离为一个既可以发送到服务器又可以添加到表的变量
$('#addRow').on('click', function() {
var rowArray = [
counter + '.1',
counter + '.2',
counter + '.3',
counter + '.4',
counter + '.5'
];
var postData = {row: rowArray};
$.ajax({
url: base_url + 'personel/createPersonel',
type: 'post',
data: postData,
dataType: 'json',
success: function(response) {
t.row.add(rowArray).draw(false);
counter++;
}
});
})
Then receive the array as $_POST['row']
in php 然后在php中将数组接收为
$_POST['row']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.