服务器等待响应时的Jquery加载程序

时间:2015-02-12 11:15:50

标签: javascript jquery

美好的一天,

我想问一下,如果可以使用jquery使用loader,当我点击任何链接并等待服务器响应时,例如。这是问题,当服务器没有立即响应并且我们处于死点时。例如,网站youtube解决了这个问题。

对不起,我的英文和谢谢

1 个答案:

答案 0 :(得分:1)

使用jQuery,可以使用beforeSend中的$.ajax参数来实现:

HTML:

<img id="loader" src="someAnimation.gif" />  <!-- loader animating GIF -->

jQuery的:

$("img#loader").hide(); // hide the loader

$.ajax({
  beforeSend: function(){ $("img#loader").show(); },  // show until you get the response
  success: function(){
    $("img#loader").hide();  // hide it again
    /* perform success operations */
  }

});

读取:http://api.jquery.com/jquery.ajax/