jQuery的AJAX加载GIF [英] jquery ajax loading gif
本文介绍了jQuery的AJAX加载GIF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何jQuery的AJAX在加工过程中添加加载GIF?我看了一些教程,他们使用 beforeSend
。但仍然没有看到装载的东西。
How do I add a loading gif during the jQuery AJAX processing? I read some tutorials, they use beforeSend
. but still not see the loading thing.
<script src="jquery-1.6.1.min.js"></script>
<script>
$.ajax({
url: "index_2.php",
dataType: "html",
type: 'POST',
data: "value=something",
beforeSend: function () {
$("#result").html('<img src="loding.gif" /> Now loding...');
},
success: function(data){
$("#result").html(data); //even add .delay(5000)
}
});
</script>
<div id="result"></div>
index_2.php
index_2.php
<?php
sleep(5);
echo $_POST['value'];
?>
我设置睡眠(5);
在 index_2.php
,它应该显示 londing.gif
在 DIV#结果
5秒,直到从数据返回 index_2.php
。
I set sleep(5);
in index_2.php
, it should show the londing.gif
in the div#result
for 5 seconds, until the data return from index_2.php
.
推荐答案
可能是一个想法,就是调用Ajax请求加载图像像你这样做,即前
may be an idea is before calling the ajax request load the image like you done ie
$("#result").html('<img src="loding.gif" /> Now loding...');
那么的onSuccess绑定数据
then onsuccess bind the data
这篇关于jQuery的AJAX加载GIF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文