Hi guys
I’m trying to figure out how to show a GIF spinner as a “busy” indicator while an ajax call is busy processing the user’s request. Can someone please help. See below my ajax call as is presently.
$.ajax({
url: '../logic/data/bank_stmt_maint.php',
method: 'POST',
data: data,
dataType: 'json'
}).success(function (data){
console.log(data);
if (data.success)
{
data = data.data;
var display = '';
var t = $('#data_table').DataTable();
t.clear().draw();
for (var i = 0; i <= data.length - 1; i++)
{
var action = '';
var option = '';
if (data[i]['status'] == 0)
{
action = '<select class="form-control selOption" id="action_'+i+'">';
action = action + '<option value="1">Allocate Entry</option>';
action = action + '</select>';
var option = '<button data-option="2" class="btn btn-green btn-sm" onclick="listAction(0,'+data[i]['id']+', this);">Go <i class="icon-caret-right"> </i></button>';
}
var alloc_user = '';
var alloc_date = '';
var alloc_to = '';
if (data[i]['allocated_by'] != null)
{
alloc_to = data[i]['allocated_to'];
alloc_user = data[i]['alloc_user_name'];
if (data[i]['allocated_by'] == -1) alloc_user = 'System';
if (alloc_user == null) alloc_user = 'Admin';
}
var status_txt = '';
if (data[i]['status'] == 1) status_txt = 'Posted';
t.row.add( [
data[i]['stmt_hdr_id'],
data[i]['tran_date'],
data[i]['tran_ref_text'],
data[i]['fmt_tran_amt'],
status_txt,
alloc_to,
alloc_user,
action,
option
] ).draw();
};
}
});
The easiest way would be to toggle whether the loading indicator displays or not. Does the ajax call get triggered by a button click or something similar?
Hi.
Yes the function that launches the ajax call is triggered by a button click. I’ve tried to toggle the display using .show() and .hide() but get no reaction at all. The GIF shows up at the bottom left corner when the page loads but it does not do anything at the trigger point when it really matters. Here’s what I’ve done. What am I missing? Or is there a better way. Thanks