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

问题描述:

美好的一天,

例如,当我单击任何链接并等待服务器响应时,我想问一下,是否可以使用jquery use loader.当服务器没有立即响应并且我们陷入困境时,这就是问题.例如,YouTube网站已解决了此问题.

I would like to ask, if is possible with jquery use loader, when I click on any links and waiting for server response for example. This is problem, when server does not respond immediately and we're in dead point. Web site youtube has this problem solved, for example.

对不起,谢谢我的英语

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

With jQuery, this can be achieved by using the beforeSend parameter in $.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/