我不知道我完全理解你的问题,但假设ajaxloader.gif是加载图像,它将永远不会显示,因为它会通过接收到的内容立即更换。
ajax请求本身就是一个足够的延迟。我觉得从成功处理了移动<img
线就足以看到图像了一会儿才新内容到达:
// Show the loading image before firing the ajax request
$('#content').html('<img src="../images/ajaxloader.gif" />');
$.ajax({
url: "<?php echo site_url('apply/processpersonaldetails'); ?>",
type: 'POST',
data: form_data,
success: function(msg) {
// New content replaces the loading image
$('#content').html(msg);
}
});
如果您仍想展示新内容之前的额外延迟,你可以使用setTimeout的方法像这样:
// Show the loading image before firing the ajax request
$('#content').html('<img src="../images/ajaxloader.gif" />');
$.ajax({
url: "<?php echo site_url('apply/processpersonaldetails'); ?>",
type: 'POST',
data: form_data,
success: function(msg) {
// Insert one second delay before showing new content (not sure why)
window.setTimeout(function() {
// New content replaces the loading image
$('#content').html(msg);
}, 1000);
}
});
考虑处理ajax错误以确保图像在请求失败时也隐藏。
你能更具体一点吗?你什么时候需要延迟?在ajax调用之间?在用新的内容替换旧内容之前?你的问题并不清楚。 – 2010-11-15 14:42:46
我有完全相同的问题,加载图标只在运行完ajax完成后“运行”。 – Dryadwoods 2013-01-28 09:43:56