-1
我有一個名爲search_gen
的變量。這個變量是由ajax生成的(代碼如下所示)。如何將可變JavaScript轉換爲數據數據表
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
}
});
例如此變量將包含JSON數據(顯示波紋管)
{"name":"room_type_name","value":$("#room_type_name").val()},{"name":"room_type_code","value":$("#room_type_code"
).val()}
如果我放置JSON以上無需使用可變它的工作示例代碼波紋管
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()})
}
})
,當我'm使用變量並放入支架aodata(seach_gen)
(代碼下方)
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)
}
});
它顯示了這樣的錯誤。
我的問題是 我如何通過我的變量search_gen
到aodata.push()
謝謝
我已經嘗試了你的建議,但它仍然不起作用。並仍然有相同的錯誤信息。 –