本文介绍了Cordova中的HTML5 localstorage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
HTML5 Local Storage是否可在Cordova / PhoneGap中使用?我试图使用它,无论是HTML5的方式和docs中指定的方式。两个都不工作。
具体来说,我试图使用ajax查询结果本地存储。我已经测试过这个查询,并且可以正常工作。
;头>
< meta http-equiv =Content-Typecontent =text / html; charset = utf-8>
< meta name =format-detectioncontent =telephone = no>
< meta name =viewportcontent =user-scalable = no,initial-scale = 1,maximum-scale = 1,minimum-scale = 1,width = device-width,height = device-height ,target-densitydpi = device-dpi>
< title> Hello World< / title>
< script src =https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.jstype =text / javascript>
< / script>
< script type =text / javascript>
$(document).ready(function(){
$(form)submit(function(){
var uname = document.getElementById(username ).value;
var pword = document.getElementById(password)。value;
var postData = {
username:uname,
password:pword
} ;
$ .ajax({
url:http://www.yellowcabsavannah.com/test.php,
type:POST,
data:postData,
async:false,
dataType:'json',
cache:false,
success:function(data){
localStorage.uname = data .username;
localStorage.pword = data.password;
alert(localStorage.uname);
}
}
});
return false;
});
});
< / script>
< / head>
< body>
< form action =>
< input type ='text'id =usernamename =usernameplaceholder =Username>
< br>
< input type ='password'id =passwordname =passwordplaceholder =password>
< br>
< input type =submitid =submitvalue =Login>
< / form>
< / body>
解决方案>
我使用了这样的本地存储:
//存储值
window.localStorage .setItem('key',value);
//检索值
value = window.localStorage.getItem('key');
//删除存储
window.localStorage.removeItem('key');
希望有帮助。
Does HTML5 Local Storage work in Cordova / PhoneGap? I am trying to use it, both the HTML5 way and the way specified in the docs. Neither work.
Specifically, I am trying to use an ajax query result for local storage. I have tested the query, and it works.
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="format-detection" content="telephone=no">
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi">
<title>Hello World</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js" type="text/javascript">
</script>
<script type="text/javascript">
$(document).ready(function () {
$("form").submit(function () {
var uname = document.getElementById("username").value;
var pword = document.getElementById("password").value;
var postData = {
username: uname,
password: pword
};
$.ajax({
url: "http://www.yellowcabsavannah.com/test.php",
type: "POST",
data: postData,
async: false,
dataType: 'json',
cache: false,
success: function (data) {
localStorage.uname = data.username;
localStorage.pword = data.password;
alert(localStorage.uname);
}
}
});
return false;
});
});
</script>
</head>
<body>
<form action="">
<input type='text' id="username" name="username" placeholder="Username">
<br>
<input type='password' id="password" name="password" placeholder="password">
<br>
<input type="submit" id="submit" value="Login">
</form>
</body>
解决方案
I've used local storage like this:
// To store a value
window.localStorage.setItem('key', value);
// To retrieve a value
value = window.localStorage.getItem('key');
// To delete a storage
window.localStorage.removeItem('key');
Hope that helps.
这篇关于Cordova中的HTML5 localstorage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!