I am making an ajax call and on success calling some more functions. During the call I am displaying the spinner before and hiding it on completion. I need to display some message with spinner like which function is getting called by success
<div id="message"><i class="fa fa-spinner fa-spin"></i></div>
is markup for spinner
function runAjax(){
$.ajax({
url:"demo_test.txt",
beforeSend:function(){
$('#message').show();
},
success:function(result){
displaymessage1();
},
complete:function(){
$('#message').hide();
}
});
}
function displaymessage1(){
$('#message').append('This is message 1');
displaymessage2();
}
function displaymessage2(){
$('#message').append('This is message 2');
displaymessage3();
}
function displaymessage3(){
$('#message').append('This is message 3');
}
As soon as the "displaymessage1()" is called, I want to see the message on spinner and then for displaymessage2() and displaymessage3();
the problem is message is not appearing until the success function completes. Once success completes, messages appearing but within fraction of second it disappears as the ajax is completed.
I need to display it to create a processing effect so, that user will come to know that which method is running.
I have also tried by setting async:false, but still it was not helpful.
Please help, Thank You