Editor.remove sends empty JSON
Editor.remove sends empty JSON
jrivault
Posts: 2Questions: 0Answers: 0
Hi,
I'm using Datatable editor, and everything seems to work quite well except for the remove button.
Indeed, the json sent to my delete api is empty. if I change the type of request to POST, I have the JSON, but with the DELETE, nothing.
Do you have an idea?
Here my js:
let ajaxBase = {
dataSrc: "",
dataType: "json",
contentType: "application/json; charset=utf-8",
processData: "false",
data: function ( data ) {
let dataJson = {};
dataJson.id = Object.keys(data["data"])[0];
dataJson = Object.assign(dataJson, data["data"][dataJson.id]);
return JSON.stringify(dataJson);
}
};
editor = new $.fn.dataTable.Editor({
ajax:{
create: $.extend(true, {}, ajaxBase, {
type: "POST",
url: ajaxUrl
}),
edit: $.extend(true, {}, ajaxBase, {
type: "PUT",
url: ajaxUrl
}),
remove: $.extend(true, {}, ajaxBase, {
type: "POST",
url: ajaxUrl + "/delete"
})
},
table: "#timesheetTable",
idSrc: "id",
fields: [
....
);
This discussion has been closed.
Replies
See the
ajax.deleteBody
option. There is an explanation in there, but in short, not all HTTP servers support body parameters on DELETE, since it is not manditory in the HTTP spec.Allan
Thanks Allan,
it works.
Strange because I don't need to set this option in my other delete request without Editor.
Is it a default configuration of Editor?
thanks again
Yes, that is the default behaviour with Editor because of that issue with some HTTP servers (off the top of my head, I can't remember which were causing the issues). So we defaulted to an option that will work for everyone and you can optionally enable body parameters for DELETE if your HTTP server supports it.
Allan