I am facing an issue with a variable named search_gen
, which is generated through an ajax request (shown below).
var search_gen;
$.ajax({
type: "POST",
url: link+module_name+'search_generator/'+module_active,
dataType: "text",
async: false,
success: function(data){
search_gen = data; //or something similar
}
});
For example, this variable will contain JSON data (shown below)
{"name":"room_type_name","value":$("#room_type_name").val()},{"name":"room_type_code","value":$("#room_type_code"
).val()}
If I directly place the JSON data without using a variable, it works fine as demonstrated in the code below
table=$('#table').dataTable({
"sScrollY": "400px",
"bFilter": false,
"bProcessing": true,
"bServerSide": true,
"sServerMethod": "GET",
"sAjaxSource": link+module_name+'populate_list/'+module_active,
"iDisplayLength": 25,
"aLengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
"columnDefs": [ {
"targets": 0,
"orderable": false
},
{
"targets": -1,
"orderable": false
} ],
"fnServerParams": function (aoData) {
aoData.push({"name":"room_type_name","value":$("#room_type_name").val()},
{"name":"room_type_code","value":$("#room_type_code").val()})
}
})
But when I try to use the variable within the aodata.push()
bracket (as shown below)
table=$('#table').dataTable({
"sScrollY": "400px",
"bFilter": false,
"bProcessing": true,
"bServerSide": true,
"sServerMethod": "GET",
"sAjaxSource": link+module_name+'populate_list/'+module_active,
"iDisplayLength": 25,
"aLengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
"columnDefs": [ {
"targets": 0,
"orderable": false
},
{
"targets": -1,
"orderable": false
} ],
"fnServerParams": function (aoData) {
aoData.push(search_gen)
}
});
It results in an error like this. enter image description here
My question is, how can I correctly pass the variable search_gen
into aodata.push()
?
Thank you