我正在玩http://www.w3.org/TR/offline-webapps/上的不完整示例
但我很难看到它的评论如下:
"renders the note somewhere", and
"report error", and
"// …"
Run Code Online (Sandbox Code Playgroud)
那么,请有人帮我写一个有效的例子吗?这是我到目前为止所得到的:
<!DOCTYPE HTML>
<html manifest="cache-manifest">
<head>
<script>
var db = openDatabase("notes", "", "The Example Notes App!", 1048576);
function renderNote(row) {
// renders the note somewhere
}
function reportError(source, message) {
// report error
}
function renderNotes() {
db.transaction(function(tx) {
tx.executeSql('CREATE TABLE IF NOT EXISTS Notes(title TEXT, body TEXT)',
[]);
tx.executeSql(‘SELECT * FROM Notes’, [], function(tx, rs) {
for(var i = 0; i < rs.rows.length; i++) {
renderNote(rs.rows[i]);
}
});
});
}
function insertNote(title, text) {
db.transaction(function(tx) {
tx.executeSql('INSERT INTO Notes VALUES(?, ?)', [ title, text ],
function(tx, rs) {
// …
},
function(tx, error) {
reportError('sql', error.message);
});
});
}
</script>
<style>
label {
display:block;
}
</style>
</head>
<body>
<form>
<label for="mytitle">Title:</label>
<input name="mytitle">
<label for="mytext">Text:</label>
<textarea name="mytext"></textarea>
<!-- There is no submit button because I want to save the info on every keystroke -->
</form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我也知道我必须将其纳入某处:
if (navigator.onLine) {
// Send data using XMLHttpRequest
} else {
// Queue data locally to send later
}
Run Code Online (Sandbox Code Playgroud)
但我不确定即使我也会这样做.
a_m*_*m0d 10
它看起来像你在追求一些东西
function save() {
if (navigator.onLine) {
// Send data using XMLHttpRequest
} else {
// Queue data locally to send later
}
}
<textarea name="mytext" onkeyup="save();"></textarea>
Run Code Online (Sandbox Code Playgroud)
但是,请使用Robusto提到的超时(我认为,这也是GMail做事的方式).
如果你担心的是"渲染某个地方",等等,你可以填写这部分内容.你必须通过从数据库中选择数据,然后将其填入你的元素来填写这个部分.页.
function renderNote(row) {
$('notes').innerHtml = $('notes').innerHtml + row.body;
}
Run Code Online (Sandbox Code Playgroud)
这是我可以根据规范目前所说的最好的方法 - 但请注意,该规范目前尚未完成,您将无法在w3网站上找到它的最终版本.
如果您对如何在本地排队数据感到好奇,即使是数组也应该为此做好准备.将每个本地请求推送到阵列的末尾(并且可能在同一时间将其保存在本地)并定期检查是否有活动的Internet连接.如果互联网连接可用,请重复弹出数组中的顶部元素并通过网络发送,直到阵列为空.
| 归档时间: |
|
| 查看次数: |
9818 次 |
| 最近记录: |