Initialize Table with blank url

Initialize Table with blank url

sbsensbsen Posts: 3Questions: 1Answers: 0

Dear All,

oTable = $('#MyDataTable').DataTable({
"ajax": {
"url": "",
"dataSrc": function (json) {
return json;
}
}
});

after this I want load this table later
oTable.ajax.url("../User/GatUserData").load();

problem is when url blank still a request goes to the base url

Thanks
sbsen.

Answers

  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin

    To some extent the behaviour you are seeing is expected. DataTables doesn't to a check to see if the URL string is empty or not, and when you make a request to an empty string the browser will just get the current URL (I remember spending about a day once debugging that on an embedded browser that was running out of memory when it should have been loading icons...).

    At the moment there is no way to initialise the ajax option with an empty string I'm afraid. Perhaps that is something that DataTables should allow - I've made a note of it.

    At the moment you would need to use $.ajax and then clear() and rows().add() to add the new data to the table yourself (which is basically all ajax.reload() does.

    Allan

  • sbsensbsen Posts: 3Questions: 1Answers: 0

    Dear Allan,

    I have changed the function _fnBuildAjax( oSettings, data, fn )

    added to check the url is empty
    if(ajax.url!=="")
    oSettings.jqXHR = $.ajax( $.extend( baseAjax, ajax ) );

  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin

    Yup - that would do it. Nice one :smile:

    Allan

  • sbsensbsen Posts: 3Questions: 1Answers: 0

    Allan you can add this fix to next release Thanks...

  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin

    The next release is likely to be a bug fix release to take account of a deprecated method in jQuery 3, with very few other features. As such it probably won't go into the next release, but rather than next major update. I'm not sure yet when that will be released.

    Regards,
    Allan

This discussion has been closed.