where can i set ajax async false ?

where can i set ajax async false ?

tonykaitonykai Posts: 21Questions: 7Answers: 0

Hello ,

i have one problem need your help about obtain page length from server-side . i use serverSide to get json data . my request is : after finished dataTable initialization , obtain customize page length from json data under server-side , then re-render table via table.page.len(json.page_size).draw('full-reset'), but i find out dataTable ajax async dafault is true .where can i set ajax async false ?

below is my code :

var page_size='';

dt=$('#example').dataTable( {
"ajax": {
"url": "data.json",
"type": "POST"
}
} ).on('xhr.dt', function ( e, settings, json, xhr ){
//Ajax event - fired when an Ajax request is completed.;
page_size=json.page_size; // obtain page_size value from server-side
});

dt.page.len(page_size).draw('full-reset');

due to dataTable ajax async dafault is true ,so i don't obtain page_size value give variable page_size .

BR
Kai

Answers

  • rf1234rf1234 Posts: 2,993Questions: 87Answers: 421
    var page_size='';
    
    dt=$('#example').dataTable( {
    ajax: {
    url: "data.json",
    type: "POST",
    async: false
    }
    } ).on('xhr.dt', function ( e, settings, json, xhr ){
    //Ajax event - fired when an Ajax request is completed.;
    page_size=json.page_size; // obtain page_size value from server-side
    });
    
    dt.page.len(page_size).draw('full-reset');
    
  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin

    Note that if you do this you will get a warning in Chrome stating that async: false is deprecated and will no longer work in future versions of Chrome (I'm not sure which version they are targeting for that).

    I would strongly suggest against setting async: false.

    Allan

This discussion has been closed.