After sending DELETE request db is updated but Editor is hanging w/o error

After sending DELETE request db is updated but Editor is hanging w/o error

lsukharnlsukharn Posts: 10Questions: 3Answers: 2
edited April 2018 in Free community support

My remove code is

                    remove: {
                         type: 'DELETE',
                         url:  '../settings/ajax/_id_',
                         success:  function ( json, status, xhr ) {
                            if ( xhr.status === 200 ) {
                                json = {};
                            }
                            success( json );
                        }
                    },

I use Flask on the backend. I get 200 every time as a response from server.

Here is the popup I get after a request is processed(see image)

This popup is shown forever until a user clicks on the 'X' button.
How do I make this popup close on success?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,642Questions: 1Answers: 10,093 Site admin

    What is the success function that you are calling on line 8 above? My guess is that is throwing an undefined error which you can check in your browser's console.

    You shouldn't actually need to provide a success Ajax callback on line 4. What does the server return when the Delete command completes?

    Allan

  • lsukharnlsukharn Posts: 10Questions: 3Answers: 2

    When I commented out code with success function I got the following screenshot and xhr response OK, response text "". I can put anything in response text, for example I tried "data: [{}]" or "data: [{id: 1, ..., ...}]" but I still get an error message attached. Also, I return JSON from the backend.
    Maybe there is special response signature that DataTables accepts for DELETE? Like in case of PUT I gotta return the entire row back to the front end in JSON, only in this case it renders w/o errors

  • allanallan Posts: 61,642Questions: 1Answers: 10,093 Site admin

    Ideally just {} should do it in the response from the server.

    It would be worth checking there are no debug messages or anything else in the output since that would cause the response to be invalid JSON, and give you the error you are getting.

    Allan

  • lsukharnlsukharn Posts: 10Questions: 3Answers: 2

    I tried to return jsonify("{}") on my Flask backend, but then I get the same popup with an error, while I don't see any errors in the browser console or network:
    Request URL: http://127.0.0.1:5000/settings/proxy/ajax/3?action=remove&data%5B3%5D%5Bid%5D=3&data%5B3%5D%5Bname%5D=hostname&data%5B3%5D%5Bport%5D=8080
    Request Method: DELETE
    Status Code: 200 OK
    Remote Address: 127.0.0.1:5000
    Referrer Policy: no-referrer-when-downgrade

    I found a hacky solution:
    success: function ( json, status, xhr ) {
    if ( xhr.status === 200 ) {
    location.reload();
    }
    }

    but I am sure it's not what you guys had in mind :)

  • kthorngrenkthorngren Posts: 20,265Questions: 26Answers: 4,764
    Answer ✓

    In Python you will want to convert an empty dictionary to JSON. What you have (return jsonify("{}") is converting a string. Try:

    return jsonify({})

    Kevin

  • lsukharnlsukharn Posts: 10Questions: 3Answers: 2

    huh, you got it @kthorngren! My bad, I should've been more attentive :)
    Thanks @allan

This discussion has been closed.