js 如何判断用户网络 是否连接

2025-03-31 08:43:47
推荐回答(1个)
回答1:

可以用jQuery中的ajax超时判断:

$.ajaxSetup({
    timeout: 1, // 1秒超时
    error: function(request, status, maybe_an_exception_object) {
        if(status == 'timeout')
            alert("网断了");
    }
});