[英]detect slow internet connection in phonegap app
我可以使用navigator.network.connection.type来检查我的phonegap应用程序中是否没有互联网,但是当连接速度很慢(几乎不存在)时如何使用任何jquery / javascript代码来检查检测这种情况?
You could use setTimeout()
to set a maximum time for a request: 您可以使用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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.