我有以下代码(其他数量)从服务器获取图像URL:
$.ajax({ url: 'Script.php',
data: {action: 'Random'},
type: 'POST',
dataType: "html",
success: function(data) {
var results = data.slice(0,-1).split('|');
var workers = [];
for(i=0; i<results.length; i++)
{
workers[i] = workers[i].split(',');
}
for(i=0; i<workers.length; i++)
{
var j = i+1
$('#random-worker' + j + '-pic').attr("src", workers[i][3]);
$('#random-worker' + j + '-name').html(workers[i][0]);
$('#random-worker' + j + '-pro').html(workers[i][1]);
$('#random-worker' + j + '-city').html(workers[i][2]);
}
}
});
另外,我有这段代码在ajax请求进程时显示加载gif
var $loading = $('.div-loading').hide();
$(document)
.ajaxStart(function () {
$loading.show();
})
.ajaxStop(function () {
$loading.hide();
});
发生的事情是Ajax已经完成并且$ loading div被隐藏,只有元素获取它们的值并且Image获得新的源。有没有办法完全结束加载过程,然后才隐藏$ loading div?
感谢。