Javascript 在phonegap应用程序中检测到缓慢的internet连接
我可以使用navigator.network.connection.type检查我的phonegap应用程序中何时没有互联网,但是当连接速度慢(几乎没有)时,如何使用任何jquery/javascript代码检查和检测这种情况???您可以使用Javascript 在phonegap应用程序中检测到缓慢的internet连接,javascript,jquery,cordova,Javascript,Jquery,Cordova,我可以使用navigator.network.connection.type检查我的phonegap应用程序中何时没有互联网,但是当连接速度慢(几乎没有)时,如何使用任何jquery/javascript代码检查和检测这种情况???您可以使用setTimeout()设置请求的最长时间: var timeout; var xhr = $.ajax({ type: "GET", url: "http://myservice.com/jsonp", data: data,
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);
$.ajax
已经有了一个超时
选项,而且这根本不能回答问题。关于超时选项的观点很好。它肯定回答了这个问题:但是当连接很慢(几乎没有)时,如何使用jquery检查和检测这种情况。如果连接时间超过10秒,我会将其定义为慢速。考虑长轮询。另外:他(和我)想在发出请求之前知道连接是否慢。如果上传时间超过10秒,我不会说连接速度慢。你完全可以留下自己的答案。这是我的。很抱歉,这不是你想要的,但这是我唯一拥有的:)