Editor Submit only runs once; need help figuring out why!

Editor Submit only runs once; need help figuring out why!

pybcgpybcg Posts: 41Questions: 10Answers: 0
var ajaxEditor = new $.fn.dataTable.Editor(
    $.extend(true, {
        ajax: function(method, url, data, success, error) {
            if (data.action == 'edit') {
                data.data = JSON.stringify(data.data);
                $.post(app_settings.editor_ajax_link,
                    data,
                    function(data, textStatus, xhr) {
                        // code
                }).fail(function(jqXHR, textStatus, errorThrown) {
                    // code
                });
            }
        }
    }, editorOpts)
);    

// Here, changedRows are just a list of IDs prefixed with '#'
ajaxEditor
.edit(changedRows, false)
.submit();

My issue is that the ajaxEditor submits data to edit ONCE successfully, and then after that, it doesn't work.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,743Questions: 1Answers: 10,111 Site admin

    You don’t appear to be calling the success callback anywhere. You need to do that (passing in the JSON response that Editor is expecting) to let it know that the request has been completed and to let it finish off its processing of that submission.

    Allan

  • pybcgpybcg Posts: 41Questions: 10Answers: 0

    @allan Is the best way to call success/error in the success/error callbacks for my post request? I tried this and it doesn't seem to work.

    var ajaxEditor = new $.fn.dataTable.Editor(
    $.extend(true, {
    ajax: function(method, url, data, success, error) {
    if (data.action == 'edit') {
    data.data = JSON.stringify(data.data);
    $.post(app_settings.editor_ajax_link,
    data,
    function(data, textStatus, xhr) {
    success()
    // code
    }).fail(function(jqXHR, textStatus, errorThrown) {
    error()
    // code
    });
    }
    }
    }, editorOpts)
    );

  • pybcgpybcg Posts: 41Questions: 10Answers: 0

    I think I'm getting there! I changed my code to the following and now I'm just getting errors about what I'm returning, which I will figure out. I will let you know if I have issues!

    var ajaxEditor = new $.fn.dataTable.Editor( $.extend(true, { ajax: function ( method, url, data, success, error ) { if (data.action == 'edit') { $.ajax( { type: method, url: url, data: data, dataType: "json", success: function (json) { success( json ); // code }, error: function (xhr, error, thrown) { error( xhr, error, thrown ); // code } }); } } }, editorOpts) );

  • pybcgpybcg Posts: 41Questions: 10Answers: 0

    The only reason I was doing it this way was to call specific functions after success/error. I realize the better way to do that is use the PostSubmit event. Would you agree?

  • allanallan Posts: 61,743Questions: 1Answers: 10,111 Site admin
    Answer ✓

    110% agree :). That’s what those event handlers are there for.

    Allan

This discussion has been closed.