Help in getting data from JSON string from code behind
Help in getting data from JSON string from code behind
srain
Posts: 11Questions: 4Answers: 0
Hi,
I am just starting out so bear with me.
I got this json string from a webmethod in c# code behind.
And I got this simple initialisation below but it doesn't seem to work?
What am i missing?
$(document).ready(function () {
$('#example').dataTable({
"bProcessing":true,
"bServerSide": true,
"sAjaxSource": "Contact.aspx/DisplayMessage",
"sServerMethod": "POST"
});
});
This discussion has been closed.
Answers
Have you fully implemented server-side processing in your aspx script (required since you have enabled server-side processing)?
Allan
Isn't this the "bServerSide": true in script as above??
Yes it is - that is why I asked if you have implemented server-side processing in your aspx script?
Sorry Allan, I must be confused or missing something somewhere.
What I have currently is a json string return from aspx.cs WebMethod.
I also have a HTML in aspx of a simple table as this
And lastly the jquery as first post.
What am i missing?
"sAjaxSource": "Contact.aspx/DisplayMessage",
sAjaxSource expects a JSON data string. That's not what your aspx script is returning.
I'd suggest reading the data source part of the manual.
Allan
Tangerine,
My aspx json string return is from my code behind of aspx page (in Contact.aspx.cs), in a web method(web method name is DisplayMessage). Here it is:
[WebMethod]
public static string DisplayMessage()
{
I son't see anything there that meeds the requirements for server-side processing, as per the manual page I linked to before. Where is the
draw
parameter being set for example? Do you really want server-side processing (again, refer to the manual)?Allan
Hi Allan,
Thanks for your patience.
I prefer not to have it to be server-side processing (redraw from server after every refresh of table).
I would ideally want it to be done in browser.
However, i thought I HAVE TO make it into server-side processing as I am getting data from my SQL database. Connecting via .cs into a dataset, and converting it into JSON string.
Maybe the question should rather be, how else can I obtain data from my database to make it work client-side?
I am using Visual Studio C# and Microsoft SQL.
Examples are mostly from php so I am confused.
Fair enough. Why do you have
"bServerSide": true,
in the above code then? :-) That is why I've been talking about server-side processing...Return the data in a JSON object. How you do that in C#? I'd suggest asking in a C# forum...!
The DataTables manual has a section about loading data from an object which might also be useful.
Allan
Hi Allan,
I managed to convert my data to JSON object, which I called jsonstr.txt.
I got it working.
However, it does not work if I don't save it as an object.
I do not want to have to save each request as an object, rather I prefer to get the data from database, and then display.
What solution should I be looking at?