开始停止恢复ajax

时间:2013-10-31 02:50:32

标签: javascript jquery ajax

这是我已经废弃的脚本,它只是一个基本的停止时间观看脚本,我想要一些如何添加简历和开始按钮的输入。而且我希望能够在停止时暂停时发送ajax调用。

var timer;
$(function () {
    $('#dateTime').html(getDateTime());
    timer = setTimeout(function () {
        update();
    }, 1000);
    $('#btn').click(function () {
        clearTimeout(timer);
        var currentdatetime = getDateTime();
    });
});

function update() {
    $('#dateTime').html(getDateTime());

    timer = setTimeout(function () {
        update();
    }, 1000);
}

function getDateTime() {
    var currentdate = new Date();
    var datetime = "Timer: " + currentdate.getDate() + "/" + (currentdate.getMonth() + 1) + "/" + currentdate.getFullYear() + " " + currentdate.getHours() + ":" + currentdate.getMinutes() + ":" + currentdate.getSeconds();
    return datetime;
}

1 个答案:

答案 0 :(得分:0)

var timer;

function resume() {
    update();
    $('#resume').off("click", resume);
    $('#pause').on("click", pause);
    // make start / resume ajax call here
}

function pause() {
    clearTimeout(timer);
    $('#resume').on("click", resume);
    $('#pause').off("click", pause);
    // make pause / stop ajax call here
}

function update() {
    $('#dateTime').html(getDateTime());

    timer = setTimeout(function () {
        update();
    }, 1000);
}

function getDateTime() {
    var currentdate = new Date();
    var datetime = "Timer: " + currentdate.getDate() + "/" + (currentdate.getMonth() + 1) + "/" + currentdate.getFullYear() + " " + currentdate.getHours() + ":" + currentdate.getMinutes() + ":" + currentdate.getSeconds();
    return datetime;
}

$(function () {
    resume();
});