AJAX Post object AND retrieve data for data table
AJAX Post object AND retrieve data for data table
KKingMCG
Posts: 2Questions: 1Answers: 0
I have used DataTables to post to a C# method and retrieve data for datatables (without sending any data to the method). What I'm interested in doing now is posting parameters in the form of an object to my C# controller and getting the data back. I'm having some trouble in finding examples of this.
$("#SearchResultsTable").DataTable({
"deferRender": true,
"ajax": {
type: "POST",
url: "/Home/MyMethod",
contentType: "application/json; charset=utf-8",
data: function(d) { return JSON.stringify(d); }
}
});
The above works.
Answers
What I can't seem to find is where I could send an object in that post, i.e.
How does this work? If I send formData in the data ajax call, how do I then get my results back from the controller?
Use
ajax.data
to submit data to the server-side. This example does that (it uses server-side processing as well, but you don't need that forajax.data
to work).Allan