I have followed an example to implement a spinner when a button is requested. This code loads a font.
My problem is that the button calls an ajax and the font is loaded after the ajax call (despite the button icon change is requested first by javascript). Both ajax and font are called from a local server. This server is not multi-task and the when the ajax is called the font is not loaded until the ajax call finishes.
Is there any way to force the browser to load the font at the beginning when the page loads?
$('.btn').on('click', function() {
var $this = $(this);
$this.button('loading');
setTimeout(function() {
$this.button('reset');
}, 800000);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.2.0/js/bootstrap.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet"/>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet"/>
<div style="margin:3em;">
<button type="button" class="btn btn-primary btn-lg " id="load" data-loading-text="<i class='fa fa-circle-o-notch fa-spin'></i> Processing Order">Submit Order</button>
<br>
<br>
<button type="button" class="btn btn-primary btn-lg" id="load" data-loading-text="<i class='fa fa-spinner fa-spin '></i> Processing Order">Submit Order</button>
</div>
UPDATE
My code has such structure:
$(button).button('loading');
$.post("/my_page",
JSON.stringify({
param: "1234",
}),
function(data)
{
// ....
$(button).button('reset');
}
)
.fail(function(xhr, status, error)
{
// error handling
$(button).button('reset');
});