国产xxxx99真实实拍_久久不雅视频_高清韩国a级特黄毛片_嗯老师别我我受不了了小说

資訊專欄INFORMATION COLUMN

ajax延遲插件

zhangwang / 2995人閱讀

最近遇到需要做ajax延遲的需求,上一段代碼記錄下:

</>復制代碼

  1. var XHRService = function(options) {
  2. this.options = options;
  3. this.reqTimer = null;
  4. };
  5. XHRService.prototype = {
  6. constructor: XHRService,
  7. req: function(options) {
  8. var that = this,
  9. defer = $.Deferred();
  10. clearTimeout(this.reqTimer);
  11. this.reqTimer = setTimeout(function() {
  12. that._req(options, defer);
  13. }, this.options.reqDelay);
  14. return defer.promise();
  15. },
  16. _req: function(options, defer) {
  17. var that = this;
  18. if (this.xhr) {
  19. this.xhr.abort();
  20. }
  21. if (typeof this.options.before === "function") {
  22. clearTimeout(this.loadingTimer);
  23. this.loadingTimer = setTimeout(function() {
  24. that.options.before();
  25. }, this.options.loadingDelay);
  26. }
  27. this.xhr = $.ajax(options).done(function(data) {
  28. defer.resolve(data);
  29. })
  30. .always(function(res, status, xhrObj) {
  31. clearTimeout(that.loadingTimer);
  32. if (typeof that.options.after === "function") {
  33. that.options.after();
  34. }
  35. if (xhrObj === that.xhr) {
  36. that.xhr = null;
  37. }
  38. });
  39. }
  40. };
  41. var xhr = new XHRService({
  42. reqDelay: 10,
  43. loadingDelay: 10,
  44. before: function() {
  45. console.log("show loading...");//顯示loadingbar
  46. },
  47. after: function() {
  48. console.log("hide loading...");//隱藏loadingbar
  49. }
  50. });
  51. xhr.req({
  52. url: url,
  53. dataType: "json"
  54. }).done(function(data) {
  55. console.log("done!");
  56. });

文章版權歸作者所有,未經允許請勿轉載,若此文章存在違規行為,您可以聯系管理員刪除。

轉載請注明本文地址:http://specialneedsforspecialkids.com/yun/86210.html

相關文章

  • performance-report頁面性能、資源、錯誤、ajax,fetch請求上報插件 完善小巧

    摘要:只做頁面性能數據的采集和上報,是比較完整和健全的數據上報插件,它可以幫你完成以下功能是比較完整和健全的數據上報插件,它可以幫你完成以下功能當前頁面上一頁面當前瀏覽器版本信息頁面性能數據信息,例如頁面加載時間,白屏時間,解析時間等當前頁面 performance-report只做頁面性能數據的采集和上報,是比較完整和健全的數據上報插件,它可以幫你完成以下功能: performance-r...

    testbird 評論0 收藏0
  • select2 和 ajax的坑

    select2,一款帶多選功能,樣式更加好看的select插件。 下方記錄坑,前方高能. 要用ajax發請求并且為select2賦初始值 $.ajax({ url : _ctx+/basInfo/listPsinfoData, data : page=1&rows=9999&flag=...

    VEIGHTZ 評論0 收藏0
  • select2 和 ajax的坑

    select2,一款帶多選功能,樣式更加好看的select插件。 下方記錄坑,前方高能. 要用ajax發請求并且為select2賦初始值 $.ajax({ url : _ctx+/basInfo/listPsinfoData, data : page=1&rows=9999&flag=...

    plokmju88 評論0 收藏0

發表評論

0條評論

zhangwang

|高級講師

TA的文章

閱讀更多
最新活動
閱讀需要支付1元查看
<