【发布时间】:2013-01-26 03:01:05
【问题描述】:
HTML5 本地存储是否在 Cordova / PhoneGap 中工作?我正在尝试使用 HTML5 方式和文档中指定的方式。都不行。
具体来说,我正在尝试使用 ajax 查询结果进行本地存储。我已经测试了这个查询,它可以工作。
<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>
【问题讨论】:
-
你确定你测试的环境支持 HTML5 localc 存储吗?
-
它在PhoneGap中没有任何问题。请向我们展示您的代码,以便我们查看是否有任何问题。
-
如何测试环境以获得本地存储支持?
-
代码已添加,@RanhiruCooray
-
查看 sn-p here。它显示了如何测试是否支持
localStorage。if(typeof(Storage)!=="undefined")。所以你确定data.username和data.password包含值?
标签: html cordova local-storage