4
我可以在我的phonegap應用程序中使用navigator.network.connection.type但沒有連接時速度慢(幾乎不存在)時檢查檢測這種情況使用任何jQuery/JavaScript代碼?在phonegap應用程序中檢測到網絡連接速度慢
我可以在我的phonegap應用程序中使用navigator.network.connection.type但沒有連接時速度慢(幾乎不存在)時檢查檢測這種情況使用任何jQuery/JavaScript代碼?在phonegap應用程序中檢測到網絡連接速度慢
你可以使用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'已經有一個'timeout'選項,另外這不回答這個問題的。 – Prinzhorn
有關超時選項的好處。它肯定回答了這個問題:*但是當連接速度很慢時(幾乎不存在)如何使用任何jquery *檢查這種情況。如果連接時間超過10秒,我會將其定義爲緩慢。 – CodingIntrigue
想長時間輪詢。另外:他(和我)在提出請求之前想知道連接是否緩慢。如果上傳時間超過10秒,我不會說連接速度很慢。 – Prinzhorn