我使用 Cordova 开发智能手机应用程序。
在这个应用程序中,我需要在向服务器发送请求之前检查互联网连接。
为了做到这一点,我使用了 Cordova Connection API,但是在设备连接到没有互联网连接的 WIFI 网络的情况下,这个 API 说我们有 WIFI 连接,
有什么方法可以检查 WIFI 网络是否可用?
最佳答案
在发送实际请求之前发送一个虚拟 ajax 请求,如果您收到错误代码为“0”,则表示没有互联网连接。
$.ajax({
url: 'TestUrl',
type: 'GET',
success: function (data) {
// Go ahead with you request
},
error: function (x, y, z) {
if (x.status == 0) {
alert("Please connect to the internet");
}
else{
alert("Other Error Occured")
}
}
});
其次你也可以让你的HTML 5导航器
var condition = navigator.onLine ? "ONLINE" : "OFFLINE";
关于android - Cordova - 检查 WIFI 连接到互联网,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20540150/