我需要使用ajax DataTable函数调用中的参数调用webMethod。但是使用此代码,控件不会转到WebMethod。
<table id="tblDetail" style="width:100%;">
<thead>
<tr>
<th>SRNO</th>
<th>TRNO</th>
<th>Name</th>
<th>Task Title</th>
<th>Task Detail</th>
<th>Start Date</th>
<th>End Date</th>
</tr>
</thead>
</table>
function DisplayCof(srno) {
var path = window.location.host;
var pathname = location.pathname;
var obj = {};
obj.srno = $.trim(srno);
//obj.cofno1 = $.trim(cofno);
$("#tblDetail").DataTable({
"ajax": {
type: "POST",
data: JSON.stringify(obj),
url: "http://" + path + pathname + "/Data_Assignment_Task",
contentType: "application/json; charset=utf-8",
dataType: "json",
"dataSrc": function (json) {
var msg = $.parseJSON(json.d);
return msg;
}
success: function (result) {
var data = $.parseJSON(result.d);
alert(data);
}
},
"columns": [
{ "data": "SRNO" },
{ "data": "TRNO"},
{ "data": "NAME" },
{ "data": "TASKTITLE" },
{ "data": "TASKDTL" },
{ "data": "STARTDT" },
{ "data": "ENDDT" }
]
});
}
[WebMethod]
public static string Data_Assignment_Task(string srno)
{
return JsonConvert.SerializeObject(MainDashboardDAC.GetAllRecById(srno));
}
我还包括脚本管理器以启用页面方法。
<asp:ScriptManager ID="scm" runat="server" EnablePageMethods="true" />
请告诉我代码中的问题,或建议我可能做出的更改。