jquery插件之定时查询待处理任务数量

学习笔记 2020/12/16 jQuery, JavaScript

使用方法:

代码如下:

$("#todo_tip").pull_todo_count();


后台返回值

代码如下:

{"todo_count":3}


js文件


代码如下:

(function ($) {
    var element;
    $.fn.pull_todo_count = function () {
        var a = $(\'0个审核待申请\');
        a.attr("href","/process/todo_list");
        a.appendTo($(this));
        $(this).hide();
        element = $(this);
        timerRequestData();
    };
    function timerRequestData() {
        $.ajax({
            url:\'/pull_todo_count\',
            type:\'get\',
            data:null,
            dataType:\'json\',
            success:function(data){
                var count = data["todo_count"];
                console.log(count);
                if(count > 0){
                    element.children("a").html(count+"个审核待申请");
                    element.show();
                }else{
                    element.hide();
                }
            }
        });
        setTimeout(timerRequestData,60000);
    }
})(jQuery);

模板html代码


代码如下:

{% if user.is_authenticated %}
  
{% endif %}


本文地址:https://www.stayed.cn/item/301

转载请注明出处。

本站部分内容来源于网络,如侵犯到您的权益,请 联系我

我的博客

人生若只如初见,何事秋风悲画扇。