aJ-47
aJ-47

Reputation: 11

DataTables forcing browser to cache data

Scenario: - a function on document-load does an aJax call and returns JSON > working OK - DataTables uses the aJax return data to draw a table > working OK - Browser click event does another aJax call returns same JSON format but with new/updated values > DataTables continues to use JSON received in step 1 - when I view the return data on the 'Network' tab it shows the correct most recent data > however, console.log continues to use the first aJax returned data set - I have used "cache": false in the aJax call, DataTables initialisation and even meta http-equiv="cache-control" content="no-cache" /> in the HTML

function myFunc(inpData) {
    $.ajax({
       url: "http://xyz/yzx/zxy.php", 
       data: mydata,
       type: 'POST'
       dataType: 'json'
       cache: false,
    }).done(function(rdata) {
       console.log(rdata); 
       $('#my-table').DataTable({
                data: rdata.visitors,
                columns: [
                    {data: 'fullName'},
                    {data: 'company'},
                    {data: 'visiting'},
                    {data: 'phone'},
                    {data: 'checkIn'},
                    {data: 'checkOut'}
                ],
                rowCallback: function(row,data,index) {
                    if(data['active'] = 1) {                                
                            $('td:eq(5)', row).html("<button type='button' class='btn btn-default chk-out-btn'>Check Out Now</button>");
                            $(row).addClass("active-visitor").attr('unqid',data['id']);
                    } else {
                        $('td:eq(5)', row).html(data['checkOut']);
                        $(row).addClass('inactive-visitor').attr('unqid',data['id']); 
                    }
                }, // end rowCallback
                order: [[4, 'asc']],
                destroy: true,
                saveState: false,
                cache: false
            });
    });

    } //end myFunc 

now when myFunc(inpData) is called again, doing console.log(rdata) continues to show the old data. When i look for the return data in the 'network' tab it has the updated data.

What could be going on???

Upvotes: 0

Views: 3389

Answers (1)

aJ-47
aJ-47

Reputation: 11

I finally fixed it

if(data['active'] = 1) 

was changed to

if(data['active'] == 1) 

Probably DataTables cast number to a string on aJax return

Upvotes: 0

Related Questions