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

Jquery loader when server is waiting for response

本文关键字:Jquery 加载 程序 等待 响应 服务器      更新时间:2023-10-19

你好,

我想问一下,当我点击任何链接并等待服务器响应时,jquery使用加载器是否可能。这就是问题所在,当服务器并没有立即响应时,我们就陷入了死胡同。例如,youtube网站就解决了这个问题。

对不起,我的英语,谢谢

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

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 */
  }
});

Readup:http://api.jquery.com/jquery.ajax/