How might I handle the server returning null after a remove operation in Editor?
How might I handle the server returning null after a remove operation in Editor?
I have gotten the delete (remove) button to work from the editor. The item is deleted on the server successfully. I get A system error has occurred (More information).
.
On examination of the return JSON, I find that it is null
. The documentation for client/server specifies an expectation of an empty object {}
.
I have attempted to intercept the null
and pass on {}
with postSubmit
, but have not met with success. Need I do this elsewhere?
Here is the modification code with debugging in place that I am working with:
editor.on ('postSubmit', function(e, json, data, action, xhr){
console.log(json);
if (action == "create") {
json.data = [json.d];
}
if (action == "remove") {
json = {};
}
console.log(json);
console.log(xhr);
});
The first console.log(json);
shows null
.
The second shows {}
.
The console.log(xhr)
shows status: 200
, StatusText: "OK"
.
The confirmation window for the delete operation stays open with the error displayed on the bottom left.
How can I transform the received null
into {}
such that the Editor will close this window, removed the row from the Datatable and continue the applications function?
Thank you for your time,
Answers
postSubmit
can be used to modify the object returned, but not to replace it. So you can't replacenull
with{}
.Are you able to change what the server returns? Or perhaps have it send back a 204 No content with not even
null
, which Editor should correctly use.Allan
I am working with SharePoint 2013 and I have no server-side permissions of note. As with many other portions of this product. I am stuck with processing what I'm sent and making it all work client side.
It took me some time to get the table to update after the create action as I kept trying to
return json.d;
or other combinations rather thanjson.data = [json.d];
. The solution was crazy simple, but I just couldn't find reference to it in the first place. I was hoping for something similarly elegant this time around.Thank you!
It seems that
null
is actually valid JSON on its own - so I think it will be correct for Editor to handle this directly.I've just committed the following change:
That will be in Editor 1.6.5 which I plan to release later today, all being well!
Thanks for flagging this up.
Regards,
Allan
Thanks indeed for committing a change. This removes a major hurdle in the project. I'd not be able to move forward without it.
If I can next model the edit feature, I'll find some way to get purchasing to allow me a license to put this in place at my workplace.
Hi @allan ,
I am seeing the same problem - DataTables not handling a 204 No Content response. I am using DataTables 1.10.1, Editor 1.7.3. & jQuery 3.4.1:
jquery.dataTables.js:3888 Uncaught TypeError: Cannot read property 'error' of undefined
at Object.success (jquery.dataTables.js:3888)
at fire (jquery.js:3291)
at Object.fireWith [as resolveWith] (jquery.js:3421)
at done (jquery.js:9533)
at XMLHttpRequest.<anonymous> (jquery.js:9785)
Kindly advise.
Regards,
Harsha
Hi @allan ,
I came across this discussion and incorporated that fix here:
Seems to work!
Regards,
Harsha
Also to note, this error occurs with ajax sourced data.
dataSrc: "",
Regards,
Harsha