0

I want add the JSON data to Datatable what i get from AJAX post Response, but my process not working, can any one suggest anythig ?

My ajax Code :

$.ajax({
    method: "POST",  
    url: "Controller",  
    cache: false,
    data: { ReqAction: "getALLUserData" }, 
    success: function(data) {
        return data;                
    }
});

as AJAX Response i am getting as :

[{
    "user_code":1,
    "user_ref_number":"100809",
    "user_grp_code":2,
    "user_name":"ememhasan",
    "user_pass":"pass123",
},
{
    "user_code":1,
    "user_ref_number":"100809",
    "user_grp_code":2,
    "user_name":"ememhasan",
    "user_pass":"pass123",
},
{ more ....}
]

So how can i use this to my Datatable ?

Thanks in Advance.

RTR
  • 5
  • 6
  • 1
    Possible duplicate of [How do I return the response from an asynchronous call?](https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) – Kaddath Feb 06 '18 at 08:26
  • The easiest way is to move your ajax request config inside Datatables using the [ajax](https://datatables.net/reference/option/ajax) option. Then use the [ajax.dataSrc](https://datatables.net/reference/option/ajax.dataSrc) option to set your data source, ie, `dataSrc: ""`. You can remove the `success` function. Otherwise you will need to do something to handle the async ajax call like the link @Kaddath provided. – K Thorngren Feb 06 '18 at 14:37

1 Answers1

0

The dataSrc Property is, You are looking for.

dataSrc: function ( json ) {
           return json.data;
         }   

This will help you definitely

Lalit Mohan
  • 464
  • 3
  • 16