Ajax success function not running...

Ajax success function not running...

jolyon2000jolyon2000 Posts: 12Questions: 0Answers: 0
edited March 2014 in Bug reports
Using v1.10.0 beta3: Callback 'success' function not running. No errors in console in Chrome ! Any ideas ?

oTable = $('#joetable').DataTable( {
dom: '<"top"p>rtS',
"ajax": function (data, callback, settings) {

settings.jqXHR = $.ajax({
"dataType": 'json',
"timeout": 20000,
"type": "POST",
"url": "/myurl/",
"data": data,
"success": function (){ alert("Callback ran!"); }
});

},
"bServerSide": true,
...
});

Replies

  • jolyon2000jolyon2000 Posts: 12Questions: 0Answers: 0
    After some playing around I discovered that the function did run, however, it also prevented the data from being rendered by datatables.
    I then tried the following which DID work:

    [code]
    settings.jqXHR = $.ajax({
    "dataType": 'json',
    "timeout": 20000,
    "type": "POST",
    "url": "/myurl/",
    "data": data,
    "success": callback
    }).done(function( data ) {
    alert("Callback ran!");
    });
    [/code]


    Any reasons why the first method does not work?
  • allanallan Posts: 54,880Questions: 1Answers: 8,601 Site admin
    The documentation ( http://datatables.net/reference/option/ajax ) says:

    > success - Must not be overridden as it is used internally in DataTables.

    The documentation then states how to work around this.

    Btw - I see you are posting a number of questions in the comments section of the pages. The comments section states that it is not for questions. If you have a question about a specific piece of documentation post post your question in a forum thread and I will update the documentation as appropriate to clarify the issue if needed.

    Allan
  • jim4nzjim4nz Posts: 1Questions: 0Answers: 0

    Hi there, just wondering then on success of dataDable data how can i make a callback to run other function

  • duderduder Posts: 1Questions: 0Answers: 0
    edited August 2014

    jim4nz, for what its worth, I was able to achieve firing a function after the data was received/parsed like so

    var oTable = $("#ProjectTable").dataTable({
        "ajax": function (d, c, s) {
            s.jqXHR = $.get('/Projects/ProjectsJson', function (data) {
                c(data);
               oTable.columnFilter({
                                sPlaceHolder: "head:after",
                                aoColumns: [
                                               { "type": "text" },
                                               { "type": "select", values: ['True', 'False'], selected: 'True' },
                                               { "type": "text" }
                                ]
                            });
                        })
                        
                    },
                    'language': { 
                        'loadingRecords': "<img src='/Content/ajax-loader.gif' />"
                    }
            })
    

    Which allowed me to load my data asynchronous, use a custom loading gif, and then call the column filter extension after the data was loaded.

This discussion has been closed.