如果-否则-本地存储不起作用/codova
If - else - Localstorage dont work / cordova
我想检查它是否是第一次启动应用程序。我在usb上通过iphone上的xcode运行我的应用程序。但每次我关闭iphone上的应用程序,然后点击手机上的图标重新启动它——就像重新启动一样——它都不会意识到这个应用程序以前是启动的。我做错了什么?
$(document).ready( function() {
if (localStorage.getItem("applaunch")) {
window.localStorage.getItem("callstatus");
}else{
//Local storage is not set, hence first time launch. set the local storage item
window.localStorage.setItem('applaunch',1);
window.localStorage.setItem("vipstatus", "0");
window.localStorage.setItem("callstatus", "0");
}
function generateUUID() {
var d = new Date().getTime();
var uuid = 'xxxxxxxxxxxxxxxyxxxxxxxxxxxxxxx'.replace(/[xy]/g,function(c) {
var r = (d + Math.random()*16)%16 | 0;
d = Math.floor(d/16);
return (c=='x' ? r : (r&0x7|0x8)).toString(16);
});
return uuid.toUpperCase();
}
window.localStorage.setItem("username",generateUUID());
var username = window.localStorage.getItem("username");
var vipstatus = window.localStorage.getItem("vipstatus");
var callstatus = window.localStorage.getItem("callstatus");
$.ajax({
type: 'post',
url: 'http://www.bla.com/action.php',
data: {
data: {"username": username, "vipstatus" : vipstatus, "callstatus" : callstatus},
},
success: function(result) {
console.log(result);
}
});
});
每次我在手机上重新启动应用程序(不是再次通过XCODE BUILDING),它都会在我的数据库中创建一个新条目——请参阅ajax。
设置一个变量,说明是否是第一次。然后只在变量为true时进行AJAX调用。
$(document).ready( function() {
var first_time;
if (localStorage.getItem("applaunch")) {
first_time = false;
}else{
//Local storage is not set, hence first time launch. set the local storage item
window.localStorage.setItem('applaunch',1);
window.localStorage.setItem("vipstatus", "0");
window.localStorage.setItem("callstatus", "0");
first_time = true;
}
function generateUUID() {
var d = new Date().getTime();
var uuid = 'xxxxxxxxxxxxxxxyxxxxxxxxxxxxxxx'.replace(/[xy]/g,function(c) {
var r = (d + Math.random()*16)%16 | 0;
d = Math.floor(d/16);
return (c=='x' ? r : (r&0x7|0x8)).toString(16);
});
return uuid.toUpperCase();
}
if (first_time) {
window.localStorage.setItem("username",generateUUID());
}
var username = window.localStorage.getItem("username");
var vipstatus = window.localStorage.getItem("vipstatus");
var callstatus = window.localStorage.getItem("callstatus");
if (first_time) {
$.ajax({
type: 'post',
url: 'http://www.bla.com/action.php',
data: {
data: {"username": username, "vipstatus" : vipstatus, "callstatus" : callstatus},
},
success: function(result) {
console.log(result);
}
});
}
});
相关文章:
- electronic BrowserWindow的最小高度和宽度在hide()show()方法之后不起作用
- 监视函数从服务返回不起作用,但作用域函数起作用
- 幻灯片滚动javascript不起作用
- 简单的javascript在Shopify中不起作用
- Recaptcha在IE7和IE8中不起作用
- Ember Data DS.Model's set函数不起作用
- JsFiddle上的鼠标事件不起作用
- 我的AngularJS表达式没有'不起作用
- 点击按钮输入不起作用
- 面向对象的Javascript代码在IE7中不起作用
- 分部隐藏在jquery中不起作用
- 在phonegap应用程序内部重定向不起作用
- Array.length似乎不起作用;console.log则显示其他情况
- $ionicplatform内的$scope不;不起作用
- 我的javascript for循环不起作用
- Meteor-添加用户自定义字段的方法不起作用
- 为什么 .focus() 不起作用,而 .css(“color”,“red”) 在同一个选择器上起作用
- Textarea必需的attribut在javascript中不起作用
- 为什么javascript:void(0)在Firefox中不起作用
- 如果-否则-本地存储不起作用/codova