How can I save ajax response in variable?
How can I save ajax response in variable?
Whale
Posts: 1Questions: 1Answers: 0
How can I save ajax response in variable data?
success function breaks the table
var table = $('#example_table'), data;
table.dataTable({
ajax: {
url: '/admin.php',
data: {
modules: 'items',
action: 'get'
},
type: 'POST',
success: function (res) {
data = res
}
},
columns: [{
data: 'id'
}, {
data: 'label'
}, {
data: 'description'
}, {
data: function (row) {
return '<button type="button" onclick="admin.item.change(' + row['id'] + ')" class="btn btn-primary">Open</button>'
}
}],
info: false,
lengthChange: false,
pageLength: 20
})
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
As far as I know, the ajax parameter of the DT configuration is not a complete ajax call. it is a hint to DT on how to deal with ajax sourced data. For a complete handling of an Ajax data source, I use JQuery's $.ajax and then invoke DT through the success parameter of that.