2

I am trying to render column contents with ajax response but it doesn't display anything in the column despite ajax response returning data,

{
    "width": "20%","targets": 6,
    "defaultContent": '',
    "render": function ( data, type, row ) {
        if(row.colData !=''){
            $url="server request url";
            var ret= row.colData
            var aydGuid=row.guid;
            var params = {relatedHID:ret,guid:aydGuid};
                $.ajax({
                    url: $url,
                    async: true,
                    data: jQuery.param(params),
                    dataType:'html'
                    }).done(function( data ) {
                        alert(data) //displays response  
                        return data //does nothing                                      
                    });
}
Ris
  • 1,152
  • 7
  • 29
  • 63
  • Possible duplicate of [How do I return the response from an asynchronous call?](http://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) – aaronofleonard Aug 12 '16 at 22:23
  • Guess you didn't read the post well. I don't have problem in getting response from AJAX. My problem is ajax response is not rendering into data table(https://datatables.net/) – Ris Aug 12 '16 at 23:56
  • Ask yourself this question: when you call return data, where do you think it's being returned to? – aaronofleonard Aug 13 '16 at 02:35

1 Answers1

4

Got it working,

    {
        "width": "20%","targets": 6,
        "defaultContent": '',
        "render": function (data, type, row, meta) {
        $urlAgent="url";
        var ret= data.join('^')
        var aydGuid=row.guid;
        var params = {relatedHID:ret,guid:aydGuid};
        var currentCell = $("#tbl_DT").DataTable().cells({"row":meta.row, "column":meta.col}).nodes(0);
           $.ajax({
                url: $urlAgent,
                data: jQuery.param(params),
                dataType:'html'
          }).done(function (data) {                                                                              
                $(currentCell).html(data);
          });
          return null;
    }
  }
Ris
  • 1,152
  • 7
  • 29
  • 63