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?

EFH52EFH52 Posts: 8Questions: 1Answers: 0
edited August 2017 in Free community support

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

  • allanallan Posts: 61,726Questions: 1Answers: 10,109 Site admin

    postSubmit can be used to modify the object returned, but not to replace it. So you can't replace null 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

  • EFH52EFH52 Posts: 8Questions: 1Answers: 0

    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 than json.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!

  • allanallan Posts: 61,726Questions: 1Answers: 10,109 Site admin

    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:

    < if ( xhr.status === 204 ) {
    > if ( xhr.status === 204 || xhr.responseText === 'null' ) {
    

    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

  • EFH52EFH52 Posts: 8Questions: 1Answers: 0

    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.

  • hnhegdehnhegde Posts: 68Questions: 17Answers: 0

    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

  • hnhegdehnhegde Posts: 68Questions: 17Answers: 0

    Hi @allan ,
    I came across this discussion and incorporated that fix here:

    3885                 var baseAjax = {
    3886                         "data": data,
    // Begin fix
    3887                         "success": function (json, status, xhr) {
    3888                                 if ( xhr.status === 204 ) {
    3889                                         json = {};
    3890                                 }
    // end fix
    3891                                 var error = json.error || json.sError;
    3892                                 if ( error ) {
    3893                                         _fnLog( oSettings, 0, error );
    3894                                 }
    3895 
    3896                                 oSettings.json = json;
    3897                                 callback( json );
    3898                         },
    3899                         "dataType": "json",
    

    Seems to work!

    Regards,
    Harsha

  • hnhegdehnhegde Posts: 68Questions: 17Answers: 0

    Also to note, this error occurs with ajax sourced data.
    dataSrc: "",

    Regards,
    Harsha

This discussion has been closed.