显示元件只有的getJSON时间超过n毫秒?有的、元件、时间、getJSON

由网友(荒落执迷)分享简介:我有一些JavaScript:I have some JavaScript:surveyBusy.show();$.getJSON(apiUrl + '/' + id).done(function (data) {...surveyBusy.hide();}).fail(function (jqXHR, textS...

我有一些JavaScript:

I have some JavaScript:

surveyBusy.show();

$.getJSON(apiUrl + '/' + id)
    .done(function (data) {
        ...
        surveyBusy.hide();
    })
    .fail(function (jqXHR, textStatus, err) {
        ...
        surveyBusy.hide();
    });

不过,我想唯一的问题 surveyBusy.show(); 如果 $的getJSON 需要更多比 N 的毫秒数。你得到一个闪烁,否则。是否有关于的getJSON API,可以做到这一点的回调?我看到没有在文档。

However, I'd like to only issue surveyBusy.show(); if $.getJSON takes more than n number of milliseconds. You get a flicker otherwise. Is there a callback on the getJSON api that can do this? I see nothing in the documentation.

推荐答案

只需使用超时。另外,我把你的隐藏code。在总是处理程序,以减少code重复。

Just use a timeout. Also, I put your "hide" code in the always handler to reduce code repetition.

var busyTimeout = setTimeout(function() { surveyBusy.show(); }, 2000);

$.getJSON(apiUrl + '/' + id)
    .done(function (data) {
        ...
    })
    .fail(function (jqXHR, textStatus, err) {
        ...
    })
    .always(function() {
        clearTimeout(busyTimeout);        
        surveyBusy.hide();        
    });
阅读全文

相关推荐

最新文章