I am using jquery datatable to list my database values. I want create a country and its state in same page while that initially the state datatable is empty.Once I create country the country id is generated and can create state with that country id in same page.It also created fine but the problem is datatable is not reloading it should show the state which was created but its not showing.The problem is country id which is generated is not passing to the ajax parameter in datatable while reloading it.
country_id=$("#country_id").val();
dataTable = $('#example').DataTable( {
"serverSide": true,
// Load data for the table's content from an Ajax source
"ajax": {
"url": datatable_url,
"type": "POST",
data:{country_id: $("#country_id").val()},
error: function () { // error handling
$(".table-grid-error").html("");
$("#table").append('<tbody class="employee-grid-error"><tr><th colspan="3">No data found in the server</th></tr></tbody>');
$("#table-grid_processing").css("display", "none");
}
},
],
});
I reloading it by
$.ajax({
url: 'url',
type: "POST",
data: {
//data
},
success: function (data) {
reload_tabless();
},
function reload_tabless() {
dataTable.ajax.reload(null, false); //reload datatable ajax
}
Please help me rectify it.