ajax html response

ajax html response

kwapsterkwapster Posts: 6Questions: 4Answers: 0

I am trying to use datatables to manage my ajax request. The server however responds with html (i have no control over this).

The html response is in the form here: https://jsfiddle.net/kwapster/jo3p56m4

Ofcourse i get** Invalid JSON response. For more information about this error, please see http://datatables.net/tn/1**

Is it possible to get this working with datatables? I have limited experience.

This is my ajax request

      $("#SelectedId").change(function () {

         $("#DetailsTable").DataTable().destroy();

  $('#DetailsTable').dataTable( {
        "ajax": {
        type: "POST",
        url: http://exampleURL.com,
        data: { id: $("#SelectedId").val() },

                success: function (data) {
            $('#market-table').html(data);
        },
        beforeSend: AddLoader,
        complete: RemoveLoader  
            }

        });
});

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,903Questions: 1Answers: 10,148 Site admin
    Answer ✓

    DataTables only expects JSON back. You could parse the HTML into JSON, but I suspect what would be a lot easier is to just make the $.ajax() call yourself to get the HTML, write it into the document and then initialise DataTables on the table that has now been inserted into the document.

    Allan

Sign In or Register to comment.