ajax json data should contain text or HTML?

ajax json data should contain text or HTML?

bwduttonbwdutton Posts: 1Questions: 1Answers: 0

We've been using datatables without issue for a while now but we encountered an issue when returning data like this:

joe bob <example@example.com>

The ajax result was properly encoded using PHP json_encode() but it looks like datatables expects the JSON payload to be proper HTML? I HTML escaped the data in the JSON payload to fix the issue but I was wondering if the JSON payload should contain text or HTML? I couldn't find anything in the documentation.

Answers

  • allanallan Posts: 63,214Questions: 1Answers: 10,415 Site admin

    Yes, DataTables takes an HTML string and will insert it into the document by default. If you wish to escape HTML entities so they display as they are, you could use the new text renderer that is included in DataTables 1.10.10:

    {
      data: 'myDataProperty',
      render: $.fn.dataTable.render.text()
    }
    

    This hasn't made it to the documentation yet - its on my job list for this week!

    Allan

This discussion has been closed.