服务器等待响应时的jQuery加载程序 [英] Jquery loader when server is waiting for response

查看:148
本文介绍了服务器等待响应时的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/

这篇关于服务器等待响应时的jQuery加载程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆