タイマーを使用している理由がわかりません。次のように、ajaxリクエストの開始時にタイマーをオンにし、成功またはエラー時にオフにすることができます。
$('#loading').show();
$.post(url, request)
.success(function(data) {
$('#loading').hide();
// Do what you want with data
})
.error(function(data) {
$('#loading').hide();
// Show error message
});
読み込み中の画像をページの中央に配置するには、そのコンテナーが高さ 100% の親内にあることを確認し、ネストされている場合は、その親のいずれもposition:relative
.
#loading {
position:relative;
width:100%;
height:100%;
}
#loading img {
margin-top: -12px; // Half images height;
margin-left: -12px; // Half images width;
position:absolute;
top:50%;
left:50%;
}
OR
#loading {
width:100%;
height:100%;
}
#loading img {
width:24px // Images width
height:auto; // If Image size changes don't mess with proportions
margin:0 auto;
margin-top:48%;
}