当互联网连接时,我需要在服务器上上传一些数据它工作正常但是当互联网断开连接时,我将所有数据保存在具有唯一ID的localStorage中,当再次连接互联网连接时,所有这些 localStorage 数据将上传到服务器上。但是对现在我的“在线”事件没有触发,即使我从设备上关闭了我的 WIFI,然后再次打开 WIFI。
document.addEventListener("deviceready",onDeviceReady, false);
function onDeviceReady()
{
alert("device ready");
checkConnection();
document.addEventListener("online",callOnlineFunction, false);
}
function checkConnection()
{
network = navigator.network.connection.type;
states[Connection.UNKNOWN] = 'Unknown connection';
states[Connection.ETHERNET] = 'Ethernet connection';
states[Connection.WIFI] = 'WiFi connection';
states[Connection.CELL_2G] = 'Cell 2G connection';
states[Connection.CELL_3G] = 'Cell 3G connection';
states[Connection.CELL_4G] = 'Cell 4G connection';
states[Connection.NONE] = 'No network connection';
return states[network];
}
function callOnlineFunction()
{
alert("call onlione function");
loginOnOnline();
getDataFromQueue();
}
function loginOnOnline()
{
checkConnection();
}