詳細が送信された後、別のページにリダイレクトしようとしています。コメントアウトされたコードを試しました。リダイレクトはしますが、データは取りません。コメントアウトすると、リダイレクトされませんが、データが取り込まれます。これを適切に説明したことを願っています。
何か案は?
<script>
var curatio = {};
curatio.webdb = {};
curatio.webdb.db = null;
curatio.webdb.open = function() {
var dbSize = 5 * 1024 * 1024; // 5MB
curatio.webdb.db = openDatabase("Curatio", "1.0", "Todo manager", dbSize);
}
curatio.webdb.createTable = function() {
var db = curatio.webdb.db;
db.transaction(function(tx) {
tx.executeSql("CREATE TABLE IF NOT EXISTS weight(ID INTEGER PRIMARY KEY ASC, todo TEXT, added_on DATETIME, date TEXT, note TEXT )", []);
});
}
curatio.webdb.addTodo = function(todoText) {
var db = curatio.webdb.db;
db.transaction(function(tx){
var addedOn = new Date();
var date = document.getElementById("date").value;
var note = document.getElementById("note").value;
tx.executeSql("INSERT INTO weight(todo, added_on, date, note) VALUES (?,?,?,?)",
[todoText, addedOn, date, note],
curatio.webdb.onSuccess,
curatio.webdb.onError);
});
}
curatio.webdb.onError = function(tx, e) {
alert("There has been an error: " + e.message);
}
curatio.webdb.onSuccess = function(tx, r) {
// re-render the data.
curatio.webdb.getAllTodoItems(loadTodoItems);
}
curatio.webdb.getAllTodoItems = function(renderFunc) {
var db = curatio.webdb.db;
db.transaction(function(tx) {
tx.executeSql("SELECT * FROM weight", [], renderFunc,
curatio.webdb.onError);
});
}
curatio.webdb.deleteTodo = function(id) {
var db = curatio.webdb.db;
db.transaction(function(tx){
tx.executeSql("DELETE FROM weight WHERE ID=?", [id],
curatio.webdb.onSuccess,
curatio.webdb.onError);
});
}
function loadTodoItems(tx, rs) {
var rowOutput = "";
var todoItems = document.getElementById("todoItems");
for (var i=0; i < rs.rows.length; i++) {
rowOutput += renderTodo(rs.rows.item(i));
}
todoItems.innerHTML = rowOutput;
}
function renderTodo(row) {
return "<li> Weight: " + row.todo + " kg " + "<br />" + " Date: " + row.date + "<br />" + " Note: " + row.note + " [<a href='javascript:void(0);' onclick='curatio.webdb.deleteTodo(" + row.ID +");'>Delete</a>]</li>";
}
function init() {
curatio.webdb.open();
curatio.webdb.createTable();
curatio.webdb.getAllTodoItems(loadTodoItems);
}
function addTodo() {
var todo = document.getElementById("todo");
curatio.webdb.addTodo(todo.value);
todo.value = "";
alert("Your weight has been added");
//window.location = 'users.html'
//location.href="users.html";
}
</script>
... ... ...
<form type="post" onsubmit="addTodo(); return false;">
<div data-role="fieldcontain">
<label for="todo">
Weight
</label>
<input name="" id="todo" placeholder="75" value="" type="text">
</div>
<div data-role="fieldcontain">
<label for="date">
Date
</label>
<input name="" id="date" placeholder="" value="" type="date">
</div>
<div data-role="fieldcontain">
<label for="note">
Notes
</label>
<input name="" id="note" placeholder="short note"></input>
</div>
<input type="submit" value="Submit" data-inline="true"/>
<a rel="external" data-role="button" data-inline="true" href="users.html">
Cancel
</a>
</form>