jQuery定时器

Ajax嵌套的定时器

$.ajax({
    type: "POST",
    data:{"hosts_list": JSON.stringify(selected_hosts), "command_str": command_str, "task_type": task_type, "role_id": role_id},
    url:"{% url "multi_task" %}",
    dataType:"JSON",
    success:function (result) {
        console.log(result);

        var timer_counter = 0;
        get_result_timer = setInterval(function () {
            // 开始获取结果
            GetTaskResult(result.task_id);
            if (timer_counter < result.timeout ){ // 还可以继续运行
            //if (timer_counter < 10  ){ // 还可以继续运行
                timer_counter += 2 ;

            }else {
          // 清除定时器 clearInterval(get_result_timer);
} },2000); }

 

posted @ 2017-08-25 22:20  Vincen_shen  阅读(187)  评论(0)    收藏  举报