Jquery plugins periodically query the number of tasks to be processed
- 2020-03-30 02:46:29
- OfStack
Usage:
$("#todo_tip").pull_todo_count();
Background return value
{"todo_count":3}
Js file
(function ($) {
var element;
$.fn.pull_todo_count = function () {
var a = $('<a>0 Review pending application </a>');
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+" Review pending application ");
element.show();
}else{
element.hide();
}
}
});
setTimeout(timerRequestData,60000);
}
})(jQuery);
Template HTML code
{% if user.is_authenticated %}
<span id="todo_tip" style="display: none;"></span>
{% endif %}