科尔多瓦 - 检查WIFI连接互联网 [英] Cordova - Checking WIFI connection to internet
问题描述
我用科尔多瓦开发智能手机应用。
I use Cordova to develop a smartphone application.
在这个程序,我需要检查发送请求到服务器之前的互联网连接。
In this app, I need to check the internet connection before send request to a server.
在为了做到这一点我用科尔多瓦连接API,但在设备连接到WiFi网络,没有互联网连接的情况下,这个API说,我们有WIFI连接,
In order to do that I use the Cordova Connection API, but in the case that the device is connected to a WIFI network with no Internet connection, this API say that we have WIFI connection,
有没有什么办法来检查,如果互联网是可用的WIFI网络上?
is there any way to check if internet is available on the WIFI network ?
推荐答案
发送假Ajax请求您发送实际的请求之前,如果你和错误code为0则表示没有互联网连接。
Send an Dummy ajax request before you send the actual request, If you get and Error Code as '0' it means there is no internet connectivity.
$.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航海家
Secondly you can also make you of HTML 5 navigator
var condition = navigator.onLine ? "ONLINE" : "OFFLINE";
这篇关于科尔多瓦 - 检查WIFI连接互联网的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!