Server-side processing stuck on "processing" when handing "success" in ajax

Server-side processing stuck on "processing" when handing "success" in ajax

sittsensittsen Posts: 3Questions: 1Answers: 0

Referring to the discussion:
https://datatables.net/forums/discussion/26602/datatables-1-10-4-server-side-processing-stuck-on-processing-error-message

I am using DataTables 1.10.12. I am wondering if there is a way to draw the table after after handling ajax "success". If I do not intercept the success "event", everything works well.

Answers

  • bindridbindrid Posts: 730Questions: 0Answers: 119

    The issue is that datatables is coded to use the success so if you intercept it, it breaks datatables.

    The most common options around this is:
    1. pull your ajax out of datatable and use the ajax success to initialize the table.
    2. instead of using success:function(){} in the ajax that is in datatables, use dataFilter:function(resp(). This approach lets you "see" the data before it gets passed to success.

    Its documented here http://api.jquery.com/jQuery.ajax/

    Its a long thread but you can see an example here: https://datatables.net/forums/discussion/comment/109582#Comment_109582

  • sittsensittsen Posts: 3Questions: 1Answers: 0

    Thank you bindrid. Would dataSrc be another option as I starting to see others suggesting that path. Do you know which is better?

  • bindridbindrid Posts: 730Questions: 0Answers: 119

    It depends on what you are trying to accomplish.
    dataSrc is used when the data is not where datatables expects to find it but it is in the format it expects.

    you use dataFilter if the data is valid but not in the format that is expected. It lets you change it.

    For example, when using use Microsoft asmx web services, you could end up with the data be serialized twice so, in my case, I deserialized it, twice, put it in the format expected and sent it on.

  • bindridbindrid Posts: 730Questions: 0Answers: 119

    One other advantage of dataFilter is that it can assist with debugging, for example


          $('#actuals').DataTable({         processing: true,         destroy: true,         ajax: {             url: "PlanF.aspx/GetMeasures",             type: "POST",             contentType: "application/json; charset=utf-8",             dataType: 'json',             data: JSON.stringify({ 'Criteria': Criteria }), dataFilter: function(reps) { console.log(reps); return reps; }, error:function(err){ console.log(err); }         },         columns: [             { "data": "HoleNo" },             { "data": "Task" },             { "data": "Length" },             { "data": "Number" },             { "data": "Width" },             { "data": "Depth" }         ]     });

    by adding the dataFilter and the error sections, you can run this code with the console open and be able to drill down and see exactly what you got from the server and see what to do with it to have datatables except it

  • sittsensittsen Posts: 3Questions: 1Answers: 0

    Thank you so much bindrid. I have gone for the dataSrc option as the data it serves my purpose. Thank you again.

This discussion has been closed.