Completely handle ajax request on my own is back firing.

Completely handle ajax request on my own is back firing.

mlov83mlov83 Posts: 3Questions: 1Answers: 0
edited January 2016 in Free community support

Looking at the example towards the bottom on this page https://datatables.net/reference/option/ajax I should be able to make an ajax request on search on the datable using the "ajax" function. I have been able to accomplish that much. However, I know I'm making this harder than it needs to be. I have a test table that I initialize like so.

  testTable =  $('#testTable').DataTable( {
        "processing": true,
        "serverSide": true,            

        "ajax": function (data) {

            data.search.value
            searchResultsForFunds(data.search.value);


           }
       }); 

and I retrieve the data like so.

     function searchResultsForFunds(d){

       var fundAndChart = JSON.stringify({ "Chart": currentWorkingChart ,"Fund":d})
       if (d.length  == 3) {
           $.ajax({
               type: "POST",

               contentType: "application/json; charset=utf-8",

               data: fundAndChart,

               url: "../compServices.asmx/searchFunds",

               dataType: "json",

               success: function(d){
                   for (i = 0; i < d.d.length; i++) {
                       testTable.row.add([d.d[i].chart, 
                                          d.d[i].fund,
                                          d.d[i].orgDefault,
                                          d.d[i].progDefault]).draw(false);
                   }

               },

               error: function(e){ alert("didn't get anywhere") }
           });


       }
   } 

my problem occurs every time I try to add records to the table it goes back to the initial call in here "ajax": function (data) basically putting me into a vicious loop. I know I must be using the "ajax:" function incorrectly but can someone help me get this right.

Thanks

This discussion has been closed.