Invalid JSON response when calling success callback with empty object

Invalid JSON response when calling success callback with empty object

grizzlyygrizzlyy Posts: 6Questions: 2Answers: 0


I'm trying to use localStorage as the data source, as shown in this example.

However, I have a problem to implement the remove action. I get an "invalid JSON response" error after calling the successCallback either with an empty data attribute, like in the linked example (success({data: []})), or with a completely empty object, like shown in the protocol definition (success({})).

Magic doesn't happen at lines 20-25:

                            linkCampaignToProjectEditorConfig['ajax'] = function (method, url, data, success, error) {
                                var project = getProjectUnderCreation();

                                if (data.action === 'create') {
                                    var output = { data: [] };
                                    var campaignId =[0]['campaign'];

                                    // TODO: remove async false
                                    var campaign = $.ajax({
                                        async: false,
                                        url: 'api/campaigns/' + campaignId

                                    localStorage.setItem('projectUnderCreation', JSON.stringify(project));

                          {'campaign': campaign});

                                } else if (data.action = 'remove') {
                                    var campaignId = Object.keys([0];
                                    project.campaigns = project.campaigns.filter(c => != campaignId);
                                    localStorage.setItem('projectUnderCreation', JSON.stringify(project));
                                    success({}); // -> invalid JSON, same with success({data: []})

Side note: I also have the same problem with the create action, despite trying various changes to comply with the communication protocol. However, for now I try to make the remove action not show the JSON error, which should be easier.

Thx in advance for your help,

This question has an accepted answers - jump to answer


  • tangerinetangerine Posts: 2,768Questions: 22Answers: 323
    } else if (data.action = 'remove') {

    That's an assignment, not a comparison.

  • grizzlyygrizzlyy Posts: 6Questions: 2Answers: 0
    edited September 14

    Thanks for pointing this error out, however it doesn't seem to be the cause of the JSON problem.

    To be more specific, I went into this conditional block in debug mode and I'm sure the callback is called with either of the two alternatives I checked.

  • kthorngrenkthorngren Posts: 10,609Questions: 25Answers: 2,416
    Answer ✓

    Possibly you are running into another error? Have you looked at your browser's console. for errors?

    Please post a link to your page or a running test case so we can help debug.


  • grizzlyygrizzlyy Posts: 6Questions: 2Answers: 0

    So actually it was indeed due to another error (not sure exactly what, since I fixed several things I thought irrelevant to this problem, but possibly it had to do with JQuery selector and nested tables).


Sign In or Register to comment.