ajax html response
ajax html response
kwapster
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
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