1

below is my code in which I send an ajax call to my web method and get data from server to populate my HTML table, as you can see I am using Jquery DataTables to accomplish the task, and it is working fine

  $('#example').DataTable({
            "ajax": {
                "dataType": 'json',
                "contentType": "application/json; charset=utf-8",
                "type": "POST",
                "url": "index.aspx/Risky",
                "dataSrc": function (json) {
                    return $.parseJSON(json.d);
                }
            },
            "columns": [
                { "data": "Prctice_Group_Risk_No" },
                { "data": "Practice_Group" },
                { "data": "Risk_Category" },
            ]
        });

my question is how can i pass a parameter with this ajax call? I have seen everywhere on net but all those examples are about where its server side processing but here i am am using client side processing , I am not using fnsServerData or fnServerParams , Can anyone help me know how to pass a parameter with my ajax call?

1 Answer 1

1

Use ajax.data option to add or modify data submitted to the server upon an Ajax request.

$('#example').DataTable({
   "ajax": {
       "dataType": 'json',
       "contentType": "application/json; charset=utf-8",
       "type": "POST",
       "url": "index.aspx/Risky",
       "data": function (d) {
          d.extra_search = $('#extra').val();
       },
       "dataSrc": function (json) {
           return $.parseJSON(json.d);
       }
    },
    "columns": [
        { "data": "Prctice_Group_Risk_No" },
        { "data": "Practice_Group" },
        { "data": "Risk_Category" },
     ]
});
Sign up to request clarification or add additional context in comments.

3 Comments

Hello Gyrocode Thanx for help but its not working , its giving me the NetworkError: 500 Internal Server Error - localhost/RiskManager/index.aspx/Risky, It does not call the function at all , I have tried all the methods described in the following link datatables.net/reference/option/ajax.data
@umer, HTTP response code 500 usually means problem with the code on the server side.
Hello @ Gyrocode.com , that is correct i guess , it is issue with the invalid json format which server denies to accept , I have put my detailed problem into this thread stackoverflow.com/questions/33752799/… Can you kindly help me on this ..

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.