Working with DataTables and ASP.NET Webservice
Working with DataTables and ASP.NET Webservice
So, I have two options, I can use JSON or AJAX. Both of them need variables passed into them. The problem is, I could not see how to do this. For some reason the datatable just sits there with a Processing... display. Here is my code:
ASP.NET side:
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public String Comment_JSON(Int32 intCustomerId, Int32 intLocationId)
{
return "[{\"Name\":\"Ajay Singh\", \"Company\":\"Ajay Store\"},{\"Name\":\"Ajay Singh1\", \"Company\":\"Ajay Store\"}]";
}
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Xml)]
public Comment[] Comment_AJAX(Int32 intCustomerId, Int32 intLocationId)
{
Comment[] obj = new Comment[2];
obj[0] = new Comment();
obj[0].Date = DateTime.Now;
obj[0].Editor = "Testor 1";
obj[0].Comments = "This is my first AJAX call";
obj[1] = new Comment();
obj[1].Date = DateTime.Now;
obj[1].Editor = "Testor 2";
obj[1].Comments = "This is my first AJAX call Too";
return obj;
}
I looked at these and they seem to display AJAX or JSON information. I used this site as my reference for that:
http://www.codeproject.com/KB/webservices/jsonwebservice.aspx
As for my DataTables....I tried this code below and still no luck.
$(document).ready(function() {
$('#example').dataTable({
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "http://localhost:1907/Comment_AJAX",
"fnServerData": function (sSource, aoData, fnCallback) {
aoData.push([{"name":"intCustomerId", "value":"1"}, {"name":"intLocationId", "value":"1"}]);
$.getJSON(sSource, aoData, function(json) {fnCallback(json)});
},
"bJQueryUI": true,
"bPaginate": false,
"bLengthChange": false,
"bFilter": false,
"bSort": false,
"bInfo": false,
"AutoWidth": false,
"aoColumns": [{ "sWidth": "200px" }, { "sWidth": "200px" }, null]
});
});
What am I missing so that I can proceed to get this to work?
ASP.NET side:
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public String Comment_JSON(Int32 intCustomerId, Int32 intLocationId)
{
return "[{\"Name\":\"Ajay Singh\", \"Company\":\"Ajay Store\"},{\"Name\":\"Ajay Singh1\", \"Company\":\"Ajay Store\"}]";
}
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Xml)]
public Comment[] Comment_AJAX(Int32 intCustomerId, Int32 intLocationId)
{
Comment[] obj = new Comment[2];
obj[0] = new Comment();
obj[0].Date = DateTime.Now;
obj[0].Editor = "Testor 1";
obj[0].Comments = "This is my first AJAX call";
obj[1] = new Comment();
obj[1].Date = DateTime.Now;
obj[1].Editor = "Testor 2";
obj[1].Comments = "This is my first AJAX call Too";
return obj;
}
I looked at these and they seem to display AJAX or JSON information. I used this site as my reference for that:
http://www.codeproject.com/KB/webservices/jsonwebservice.aspx
As for my DataTables....I tried this code below and still no luck.
$(document).ready(function() {
$('#example').dataTable({
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "http://localhost:1907/Comment_AJAX",
"fnServerData": function (sSource, aoData, fnCallback) {
aoData.push([{"name":"intCustomerId", "value":"1"}, {"name":"intLocationId", "value":"1"}]);
$.getJSON(sSource, aoData, function(json) {fnCallback(json)});
},
"bJQueryUI": true,
"bPaginate": false,
"bLengthChange": false,
"bFilter": false,
"bSort": false,
"bInfo": false,
"AutoWidth": false,
"aoColumns": [{ "sWidth": "200px" }, { "sWidth": "200px" }, null]
});
});
What am I missing so that I can proceed to get this to work?
This discussion has been closed.