2017-01-22 2 views
0

У меня есть данные, которые я загружаю через Ajax. на стороне сервера. Я заготовлю данные для таблицы и готовлю другие данные для другой вещи. Я хочу, помимо загрузки таблицы, сделать что-то еще с другими данными, которые я подготовил , поэтому я добавил в свой код ajax событие успеха, но оно заменяет загрузку таблицы, и я могу только сделать другую вещь . Я не могу отделить загрузку таблицы от другой, потому что они связаны, что означает, что на другую влияет влияние загрузки таблицы (изменений)Сделайте что-нибудь рядом с таблицей загрузки

я попытался также fnDrawCallback, но я не знаю, как передать данные другой вещи Вот код Ajax с событием успеха:

"ajax": { 
     "url": "/Entreaties/GetEntreaties", 
     "data": function (d) { 
      d.status = 0; 
      d.firstLoad = firstLoad;     
      d.jAdvanceSearch = JSON.stringify(new AdvanceSearch()); 
      d.freeText = $("#table_filter input").val(); 
     }, 
     "type": "POST", 
     "dataType": "json", 
     success: function (data) { 
      $.each(data.contactWaySum, function (key, value) { 
       alert(key + ": " + value.ContactWay); 
      });     
     }, 
     error: function (xhr, textStatus, errorThrown) { 
      console.log(xhr.responseText); 
     } 
    }, 

Благодарим за помощь.

ответ

0

Если вы правильно поняли, вы использовали встроенный ajax в DataTable, но остановились, потому что вы хотели сделать несколько вещей одновременно. Если это так, вернитесь к использованию ajax DataTable и используйте функцию dataFilter, чтобы отделить их и применить их.

Вот пример:

// If your server side sends back somehting that looks like this for the data table (this is what it is expecting) 

      {draw:1, recordTotal:20, recordsFilter:20, data:dataSet } 

      // adjust your json to look like 


      // If the json object return looks like what the 
      { dataTableData:{draw:1, recordTotal:20, recordsFilter:20, data:dataSet }, otherStuffData: otherData} 

      $("#sometable").DataTable({ 
       // other data table stuff left out to save space 
       "serverSide": true, 
       "ajax": { 
        "url": "you url" , 
        "data": function (ssp) { 
         // Do the stuff you need to to get your paramerters ready 
         // server side parameters (ssp) are documented at http://datatables.net/manual/server-side 
         // in addition to the ssp parameters, the name of the column is pulled from the table header column 


         return ssp; 

        }, 
        type: "POST", 
        contentType: "application/json; charset=utf-8", 
        dataType: "json", 
        error: function (a, b, c, d) { debugger; }, 
        dataFilter: function (data) { 

         // call function or what ever you need to do with the other data here 

         doOtherStuff(data.otherStuffData); 

         // the web method returns the data in a wrapper 
         // so it has to be pulled out and put in the 
         // form that DataTables is expecting. 

         //return just the datatable data here 
         return JSON.stringify(data.dataTableData); 
        } 
       } 
      }); 
Смежные вопросы