防止UI因Ajax调用而冻结

Tim*_*ans 1 ajax jquery

位于第192、193、196、197、199 和205行的https://github.com/DjangoCoder/DjangoGUI/blob/master/templates/base.html上注释掉的代码冻结了UI。我几乎无法使用文本编辑器。我想取消注释这些行。有没有一种方法可以不冻结UI?该网站位于

http://198.144.178.112:8000
Run Code Online (Sandbox Code Playgroud)

use*_*367 5

您需要将async设置为true。那就是async参数的目的是允许这种情况在后台发生,而浏览器继续执行其余代码。

编辑:对不起,这是更多信息。

从第173行开始,您应该将ajax函数的初始化中的async参数更改为true。像这样:

function testConnection() {
    $.ajax({
        url: "/",
        cache: false,
        async : true,
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            $('#errorbar').css({'height': ($('#header').height()) + 'px'}).show();
        },
        success: function(html){
            $('#errorbar').hide();
        }
    });
}
Run Code Online (Sandbox Code Playgroud)

  • 好吧,您首先搜索代码中唯一包含单词“ async”的行,然后将“ false”更改为“ true”。 (5认同)