Android jQuery mobile ajax检测设备是否没有internet连接
我正在开发一款android应用程序,它需要检测互联网连接,如果设备没有互联网连接,则会发出警告,提示设备没有互联网连接 这是我的密码:Android jQuery mobile ajax检测设备是否没有internet连接,android,ajax,jquery-mobile,cordova,Android,Ajax,Jquery Mobile,Cordova,我正在开发一款android应用程序,它需要检测互联网连接,如果设备没有互联网连接,则会发出警告,提示设备没有互联网连接 这是我的密码: <script> var lform = $("#loginform"); function verifyfirst(){ if($( "#txtusername" ).val() == "" || $( "#txtpassword" ).val() == "") {
<script>
var lform = $("#loginform");
function verifyfirst(){
if($( "#txtusername" ).val() == "" || $( "#txtpassword" ).val() == "")
{
return;
}
else
{
$.mobile.loading("show");
$.getJSON("http://url/verifyfirst.php?callback=?", lform.serialize(),function(data)
{
if (data.verified == "v1")
{
localStorage.setItem("datausername", data.txtusername);
if (localStorage.getItem("datausername") == "admin")
{
location.href="admin.html";
}
else
{
//$.mobile.changePage( "menu.html", { changeHash: true });
location.href="menu.html";
}
}
else
{
$("#popuptext").html("<b>The account you've entered is not associated with Happy Au Pair. Please check your username or password.</b>");
$( "#popupAfter" ).popup( "open", {
positionTo: "window",
transition: "pop" });
$.mobile.loading("hide");
}
}).fail(function(data){
$("#popuptext").html("<b>There is a problem with your login, please try again later.</b>");
$( "#popupAfter" ).popup( "open", {
positionTo: "window",
transition: "pop"});
$.mobile.loading("hide");
});
}
}
</script>
变量lform=$(“#loginform”);
函数verifyfirst(){
if($(“#txtsername”).val()==”|$(“#txtpassword”).val()==”)
{
返回;
}
其他的
{
$.mobile.loading(“show”);
$.getJSON(“http://url/verifyfirst.php?callback=?,lform.serialize(),函数(数据)
{
如果(data.verified==“v1”)
{
setItem(“datausername”,data.txtusername);
if(localStorage.getItem(“datausername”)=“admin”)
{
location.href=“admin.html”;
}
其他的
{
//$.mobile.changePage(“menu.html”,{changeHash:true});
location.href=“menu.html”;
}
}
其他的
{
$(“#popuptext”).html(“您输入的帐户与Happy Au Pair没有关联。请检查您的用户名或密码。”);
$(“#popupAfter”).popup(“打开”,{
位置至:“窗口”,
过渡:“pop”};
$.mobile.load(“隐藏”);
}
}).失败(功能(数据){
$(“#popuptext”).html(“您的登录有问题,请稍后再试。”);
$(“#popupAfter”).popup(“打开”,{
位置至:“窗口”,
过渡:“pop”};
$.mobile.load(“隐藏”);
});
}
}
我试着在这里组合,但不起作用:
<script>
var online = navigator.onLine;
if(online) {
//I placed the ajax here
} else {
alert("Internet Connectivity is not available.");
}
</script>
var online=navigator.online;
如果(在线){
//我把ajax放在这里
}否则{
警报(“互联网连接不可用”);
}
请帮我做到这一点。我正在使用build.phonegap.com导出apk文件。
提前谢谢
var condition = navigator.onLine ? "ONLINE" : "OFFLINE";
你可以在线或离线使用它。您还可以通过进行ajax调用来测试它
$.ajax({
url: url,
type: 'GET',
contentType: "application/json;charset=utf-8",
success: function (data) {
// Yor success logic
},
error: function (request) {
// alert(request.responseText);
// alert(request.status);
if(request.status==0)
{
alert("Please connect to the internet");
}
}
});
你可以在线或离线使用它。您还可以通过进行ajax调用来测试它
$.ajax({
url: url,
type: 'GET',
contentType: "application/json;charset=utf-8",
success: function (data) {
// Yor success logic
},
error: function (request) {
// alert(request.responseText);
// alert(request.status);
if(request.status==0)
{
alert("Please connect to the internet");
}
}
});
你可以在线或离线使用它。您还可以通过进行ajax调用来测试它
$.ajax({
url: url,
type: 'GET',
contentType: "application/json;charset=utf-8",
success: function (data) {
// Yor success logic
},
error: function (request) {
// alert(request.responseText);
// alert(request.status);
if(request.status==0)
{
alert("Please connect to the internet");
}
}
});
你可以在线或离线使用它。您还可以通过进行ajax调用来测试它
$.ajax({
url: url,
type: 'GET',
contentType: "application/json;charset=utf-8",
success: function (data) {
// Yor success logic
},
error: function (request) {
// alert(request.responseText);
// alert(request.status);
if(request.status==0)
{
alert("Please connect to the internet");
}
}
});
在发送实际请求之前,尝试发送虚拟ajax请求
$.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")
}
}
});
Phonegap也有,当连接发生变化时会触发whish在发送实际请求之前尝试发送虚拟ajax请求
$.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")
}
}
});
Phonegap也有,当连接发生变化时会触发whish在发送实际请求之前尝试发送虚拟ajax请求
$.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")
}
}
});
Phonegap也有,当连接发生变化时会触发whish在发送实际请求之前尝试发送虚拟ajax请求
$.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")
}
}
});
Phonegap也有,当连接发生变化时,会触发whish我应该在
url:
中输入什么?您的ur到服务器。。。。(虚拟url),用于检查是否存在internet连接我应该在url:
中输入什么?您的ur到服务器。。。。(虚拟url),用于检查是否存在internet连接我应该在url:
中输入什么?您的ur到服务器。。。。(虚拟url),用于检查是否存在internet连接我应该在url:
中输入什么?您的ur到服务器。。。。(虚拟url),你可以展示我将如何在我的代码中实现这一点吗?你的url可以检查互联网吗?你可以展示我将如何在我的代码中实现这一点吗?你的url可以检查互联网吗?你可以展示我将如何在我的代码中实现这一点吗?你的url可以检查互联网吗在我的代码中实现这一点。您的url用于检查internet