weixin_33724659 2015-05-15 11:17 采纳率: 0%
浏览 29

如何创建秒表

I have an Ajax call like this:

$(document).on('submit', '#formPropiedades', function(event) {
    event.preventDefault();
    var content = {}, url = "http://www.xxxxyzzz.com/xxx/yyy/web/ajax.php";    
    $("#dialog1").dialog("open");
    var posting = $.post(url, {
        im_core: 'saveAllAdds',
        idFeed: <?php echo $_POST['idFeed'] ?>,
        pais: <?php echo $pais1?>
    }).done(function(data) {
        if (data == 1)
            $(".overlay-bg1").html("Suces....");
        else
            $(".overlay-bg1").html(data);
    }); 
<?php } ?>  
});

And my HTML looks like this:

<div id="dialog1" title="Attention!!" style="width:60%">
    <div class="overlay-bg1">Saving the Adds....</div>
</div>

The code for opening the jQuery UI Dialogue is like this

$(function () {
    $("#dialog1").dialog({
        autoOpen: false,
        show: {
            effect: "blind",
            duration: 1000
        },
        hide: {
            effect: "",
            duration: 1000
        },  
    });
});

I want to Show a timer in the POPUP which should start when the Ajax call is done and stop when I get the response. It should look like a Stop watch

  • 写回答

3条回答 默认 最新

  • weixin_33698823 2015-05-15 11:20
    关注

    before ajax start:

    var startTime = (new Date()).getTime();
    

    when you get the response:

    var nowTime = (new Date()).getTime();
    var theTime = nowTime - startTime;
    

    UPDATE:

    with a visual timer demo

    UPDATE:

    seconds and minutes demo

    UPDATE:

    with number round demo

    评论

报告相同问题?