My task involves modifying the data sent to an ajax call within the complete function.
For example, I initialize var total = 1;
after the ajax call has begun execution.
function test(total) {
total = total;
alert("total : " + total);
}
$('#call_analysis_basic_table').DataTable( {
"processing": true,
"serverSide": true,
"iDisplayLength": 100,
"ajax":{
type: "POST",
url :"http://localhost:8050/phpservice/index.php", // json datasource
data: {
"rec" : total,
"phone" : "d123",
"from_date" : "14-05-2016" ,
"to_date" : "20-09-2017"
},
error: function(){
alert("error");
},
complete: function(data){
total = data.responseJSON.recordsTotal;
test(total);
}
}
} );
Initially, the value of the parameter rec
is 1
. However, upon updating the value of total in the complete function (now set at 20), when I navigate to page 2 of the table, the ajax call reverts back to sending a rec value of 1 instead of 20.
Why does this happen? Even though I modify the parameter's value in the complete function, it reverts back to the original value during subsequent ajax calls.