Searchbuilder javascript errors when sending JSON
Searchbuilder javascript errors when sending JSON
Ok I posted this as a reply but wanted to make a new post. Very strange here is my table code I stripped it down for example but it works:
$(document).ready(function() {
var table = $('#aiDataTable').DataTable({
dom: 'Qlfrtip',
ajax: {
url: 'aimgmtController.cfm',
type: 'POST',
contentType: "application/json",
data: function ( d ) {
return JSON.stringify( d );
},
dataSrc: 'data'
},
searchBuilder: {
searchBuilder: true
},
serverSide: true,
processing: true,
search: {
return: true
},
pageLength: 25, // Initial number of entries per page
columnDefs: [
{
targets: 0, // UHID column
data: 'UHID',
searchBuilderTitle: 'UHID',
},
],
order: []
});
table.searchBuilder.container().prependTo(table.table().container());
});
Ok so what happen on initial page load everything looks great json is sent data displays. However, when I click the UHID column I just a javascript error:
Uncaught TypeError: Cannot create property 'searchBuilder' on string '{"draw":2,"columns":[{"data":"UHID","name":"","searchable":true,"orderable":true,"search":{"value":"","regex":false}}],"order":[{"column":0,"dir":"asc"}],"start":0,"length":25,"search":{"value":"","regex":false}}'
at HTMLTableElement.<anonymous> (datatables.min.js:26:59267)
at HTMLTableElement.dispatch (jquery.min.js:2:43064)
at v.handle (jquery.min.js:2:41048)
at Object.trigger (jquery.min.js:2:71515)
at HTMLTableElement.<anonymous> (jquery.min.js:2:72110)
at Function.each (jquery.min.js:2:3003)
at S.fn.init.each (jquery.min.js:2:1481)
at S.fn.init.trigger (jquery.min.js:2:72086)
at R (datatables.min.js:16:47659)
at Tt (datatables.min.js:16:26510)
Now If I simply remove this part:
contentType: "application/json",
data: function ( d ) {
return JSON.stringify( d );
},
No javascript errors but now the data is not being sent in json format anymore. I feel like I'm really close but why no js errors when I remove it (works perfect) I add that js errors and it won't submit. I really want the data in json format as its difficult to work with the default data in coldfusion.
Replies
See my reply in your other thread.
Kevin