我有一个数据表,我正在通过Ajax加载。 在服务器端,我正在预备表的数据,并为另一件事准备另一个数据 我希望,除了表格加载之外,还要用我准备好的其他数据做另一件事 所以我在我的ajax代码中添加了一个成功事件,但它取代了表加载,我只能做另一件事 我无法将表加载和其他东西分开,因为它们是连接的,意味着另一个东西受到表加载(更改)的影响
我也试过fnDrawCallback但我不知道如何传递其他东西的数据 这是带成功事件的Ajax代码:
"ajax": {
"url": "/Entreaties/GetEntreaties",
"data": function (d) {
d.status = 0;
d.firstLoad = firstLoad;
d.jAdvanceSearch = JSON.stringify(new AdvanceSearch());
d.freeText = $("#table_filter input").val();
},
"type": "POST",
"dataType": "json",
success: function (data) {
$.each(data.contactWaySum, function (key, value) {
alert(key + ": " + value.ContactWay);
});
},
error: function (xhr, textStatus, errorThrown) {
console.log(xhr.responseText);
}
},
谢谢大家的帮助
答案 0 :(得分:0)
如果我理解你的话,你使用的是内置的DataTable ajax,但因为你想一次做几件事而停止了。如果是这样,请返回使用DataTable ajax并使用dataFilter函数将它们分开并应用它们。
以下是一个例子:
// If your server side sends back somehting that looks like this for the data table (this is what it is expecting)
{draw:1, recordTotal:20, recordsFilter:20, data:dataSet }
// adjust your json to look like
// If the json object return looks like what the
{ dataTableData:{draw:1, recordTotal:20, recordsFilter:20, data:dataSet }, otherStuffData: otherData}
$("#sometable").DataTable({
// other data table stuff left out to save space
"serverSide": true,
"ajax": {
"url": "you url" ,
"data": function (ssp) {
// Do the stuff you need to to get your paramerters ready
// server side parameters (ssp) are documented at http://datatables.net/manual/server-side
// in addition to the ssp parameters, the name of the column is pulled from the table header column
return ssp;
},
type: "POST",
contentType: "application/json; charset=utf-8",
dataType: "json",
error: function (a, b, c, d) { debugger; },
dataFilter: function (data) {
// call function or what ever you need to do with the other data here
doOtherStuff(data.otherStuffData);
// the web method returns the data in a wrapper
// so it has to be pulled out and put in the
// form that DataTables is expecting.
//return just the datatable data here
return JSON.stringify( data.dataTableData);
}
}
});