Editor: Option 'ajax' just working with string *closed*

Editor: Option 'ajax' just working with string *closed*

jgessingerjgessinger Posts: 38Questions: 6Answers: 0
edited June 2016 in Free community support

This is working fine:

var editor = new $.fn.dataTable.Editor({
    ajax: '/myController/myAction'
});

Referring to ajax.data
This tries to send an ajax request to [object] instead to the url (when I watch the request in developer tools):

var editor = new $.fn.dataTable.Editor({
    ajax: {
        data: {
            __RequestVerificationToken: $('#example').data('token')
        }
    }
});

This tries to send an ajax request to function ():

var editor = new $.fn.dataTable.Editor({
    ajax: function () {
        // ...
    }
});

So whenever I set something other than a string to the option 'ajax', the request url is not properly read out of the option. Can you confirm this or am I doing something wrong?

Replies

  • allanallan Posts: 61,821Questions: 1Answers: 10,127 Site admin

    There is no url in your second code block, which is why it isn't working. There is no where for it to send (so it is compounding that error by using toString() of the object (again, since there is no url property).

    In the last case, with the function, you would specify where you want it to send the data inside the function - i.e. you've got complete control.

    Allan

  • jgessingerjgessinger Posts: 38Questions: 6Answers: 0
    edited June 2016

    Oh I'm sorry. I tested it with 'url' but forgot to write it in the second code block. Of course I meant:

    var editor = new $.fn.dataTable.Editor({
        ajax: {
            url: '/myController/myAction',
            data: {
                __RequestVerificationToken: $('#example').data('token')
            }
        }
    });
    

    Results in a POST request to '[object]': http://postimg.org/image/e9t3lo0vf/
    An the third block results in a POST request fo 'function': http://postimg.org/image/qxoh8wfor/

    And I get an alert:
    DataTables warning: table id=example - Ajax error. For more information about this error, please see http://datatables.net/tn/7

    Edit:
    Oh no ... I am sorry for this, I initialized the dataTables instance with the option:

    ajax: {
        url: editor.s.ajax
    }
    

    So the initial request is of course sending the request to an object or function and it can't work. I save the url to a variable now :) I just failed to see that I also have to change this line in my code.

  • allanallan Posts: 61,821Questions: 1Answers: 10,127 Site admin

    Nice one. Good to hear you got it sorted. Thanks for posting back!

    Allan

This discussion has been closed.