abort previous ajax call in datatables 1.10

abort previous ajax call in datatables 1.10

datatradersdatatraders Posts: 7Questions: 0Answers: 0
edited April 2014 in DataTables 1.10
Hi there,

my previous implementation of the function doing the ajax call is not working in datatables 1.10 to abort the previous ajax call:

[code]// Aborting the previous XHR;

if (settings.jqXHR)
settings.jqXHR.abort();

settings.jqXHR = $.ajax({ ... }[/code]

how can I get the expected behavior back?

best regards - Jens

Replies

  • datatradersdatatraders Posts: 7Questions: 0Answers: 0
    edited April 2014
    I replaced

    [code]settings.jqXHR[/code]

    now with

    [code]settings.nTable.jqXHR[/code]

    That seems to work.
  • allanallan Posts: 63,687Questions: 1Answers: 10,500 Site admin
    Good to hear you got it working (although slightly surprised, since the jqXHR isn't attached to the table node, it is still on the settings object).

    Allan
  • datatradersdatatraders Posts: 7Questions: 0Answers: 0
    edited April 2014
    mmmh... perhaps you would have a look at my method. With settings.jqXHR the call could not become aborted.

    [code]function (data, callback, settings) {
    //data manipulation here ...
    // ...

    // Aborting the previous XHR;

    if (settings.nTable.jqXHR)
    settings.nTable.jqXHR.abort();

    settings.nTable.jqXHR = $.ajax({
    "url": "/",
    "data": data,
    "success": function (json) {
    $(settings.oInstance).trigger('xhr', settings);
    callback( json );
    },
    "dataType": "json",
    "cache": false,
    "type": "post",
    "error": function (xhr, error, thrown) {
    xCore.systemError("", xhr, error);
    return false;
    }
    });
    }
    [/code]
  • allanallan Posts: 63,687Questions: 1Answers: 10,500 Site admin
    That is your fnServerData (optionally it could be called `ajax` in 1.10) function is it?

    Why are you assigning the `jqXHR` object to `nTable` ?

    This is where DataTables does its assignment of `jqXHR` : https://github.com/DataTables/DataTablesSrc/blob/master/js/core/core.ajax.js#L95 . So for fnServerData you would need to assign it yourself. If you are using the new `ajax` option, return the XHR object from your function.

    Allan
  • datatradersdatatraders Posts: 7Questions: 0Answers: 0
    ahh... I see .. that is exactly what I want to do. This was my ajax function. I thought fnServerdata == ajax but actually it's not.

    okay..thanks. now it works.
This discussion has been closed.