JQuery DataTable passes parameter to ajax call to asp.net

below is my code in which I send an ajax call to my web method and get data from the server to populate my HTML table, as you can see that I am using JQuery DataTables to complete the task, and it works great

  $('#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 using this ajax call? I have seen everywhere on the network, but all these examples relate to where its server part is processed, but here I use client-side processing, I do not use fnsServerData or fnServerParams. Can someone help me find out how to pass a parameter using my ajax call?

0
source share
1 answer

ajax.data , Ajax.

$('#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" },
     ]
});
+1

Source: https://habr.com/ru/post/1615390/


All Articles