jqueryajax加载gif

jqueryajax加载gif,jquery,ajax,Jquery,Ajax,如何在jQuery AJAX处理过程中添加加载gif?我读了一些教程,它们在发送前使用。但还是看不到装载的东西 <script src="jquery-1.6.1.min.js"></script> <script> $.ajax({ url: "index_2.php", dataType: "html", type: 'POST', data: "value=something", beforeSend: function () { $("#r

如何在jQuery AJAX处理过程中添加加载gif?我读了一些教程,它们在发送前使用
。但还是看不到装载的东西

<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>

$.ajax({
url:“index_2.php”,
数据类型:“html”,
键入:“POST”,
数据:“值=某物”,
beforeSend:函数(){
$(“#结果”).html('Now loding…');
},
成功:函数(数据){
$(“#result”).html(数据);//偶数添加.delay(5000)
}
});
index_2.php

<?php
sleep(5);
echo $_POST['value'];
?> 


我设置
睡眠(5)
index_2.php
中,它应该在
div#result
中显示
londing.gif
5秒钟,直到数据从
index_2.php

返回可能是一个想法,在调用ajax请求之前,像ie那样加载图像

$("#result").html('<img src="loding.gif" /> Now loding...');
$(“#结果”).html('Now loding…');

然后在成功绑定数据时,请查看
$.ajaxStart()
函数,该函数将在任何Ajax请求启动时执行(显然)


查看详细信息。

有两种方法。我的首选方法是将函数附加到元素本身上的ajaxStart/Stop事件

$('#loadingDiv')
    .hide()  // hide it initially
    .ajaxStart(function() {
        $(this).show();
    })
    .ajaxStop(function() {
        $(this).hide();
    })
;

每当您进行任何ajax调用时,ajaxStart/Stop函数都将启动。

是否可能是您将gif的名称弄错了?您在JS中指定
loding.gif
,然后在问题文本中指定
londing.gif
,但您的意思可能是
load.gif
?您看到ajax请求的结果了吗?$(document.html('Now loding…');这样行吗