I'm using the below jQuery snippet for an ajax loading image which I use on numerous sites, for some reason it wont disply the loading image when an ajax request is fired.
jQuery:
$(".loading").hide().ajaxStart(function() {
$(this).show();
}).ajaxStop(function() {
$(this).hide();
});
Example Ajax call (working as expected and returning correct data):
$('#list').change(function() {
var vCID = 1;
if ($.trim(vCID) && vCID != 0)
{
var vData = {aid:1001,id:vCID};
$.ajax(
{
url : "ajax.php",
type: "POST",
data : vData,
success: function(data, textStatus, jqXHR)
{
$('#itemList').html(data);
}
});
}
});
HTML:
<div class="loading"> </div>
CSS:
.loading {
width: 40px;
height: 40px;
margin: 10px auto 0 auto;
background: url('images/loading.gif') no-repeat;
}
The HTML code is being affected by the jQuery as display: none is being added on page load, there are no errors and if I change display: block on the HTML via firebug the loading.gif image shows up.
Any help greatly appreciated.