Searchbuilder javascript errors when sending JSON [solved]
Searchbuilder javascript errors when sending JSON [solved]

A better solution to the following discussions:
#76987
#76989
As the title and those threads explain the issue. Here is a solution that doesn't involve changing library source code:
set processData
to false
and change beforeSend
as follow:
ajax: {
url: `/url`,
type: 'POST',
contentType: "application/json",
processData: false, // "tells jquery not to process or transform the data object before sending it to the server"
data: function (d) {
d.custom_filters = getFilters();
return d; // do not JSON.stringify in here and return object
},
beforeSend: (xhr, settings) => {
xhr.setRequestHeader('Content-Type', 'application/json; charset=utf-8');
xhr.overrideMimeType('application/json');
if (typeof settings.data !== 'string') {
settings.data = JSON.stringify(settings.data);
}
},
},
Replies
Thanks for posting this! I've committed a new feature for DataTables 2.3 which addresses the issue highlighted here. Instead of using
ajax.data
to return a JSON string, I've added a newajax.submitAs
option which can be set tojson
. This ensures that the original data object, remains an object all the way through thepreXhr
process.Planning to release 2.3 next month.
Allan