gpt4 book ai didi

javascript - 在 phonegap 应用程序中检测慢速互联网连接

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:18:25 26 4
gpt4 key购买 nike

我可以使用 navigator.network.connection.type 检查当我的 phonegap 应用程序没有互联网时,但是当连接很慢时(几乎没有)如何检查检测这种情况使用任何 jquery/javascript 代码??

最佳答案

您可以使用 setTimeout() 来设置请求的最长时间:

var timeout;
var xhr = $.ajax({
type: "GET",
url: "http://myservice.com/jsonp",
data: data,
success: function(msg){
// All went OK
if(timeout != null) clearTimeout(timeout);
}
});

timeout = setTimeout(function() {
// Request took >= 10 seconds
// We could kill it?
xhr.abort();
// Or send a message to the user and ask whether they want to continue
if(!confirm("Network connection is taking longer than usual to complete. Continue waiting?")) {
xhr.abort();
}
}, 10000);

关于javascript - 在 phonegap 应用程序中检测慢速互联网连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18998089/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com