提交详细信息后,我正在尝试重定向到其他页面。我已经尝试了注释掉的代码。它确实会重定向,但不会接收数据。当我将其注释掉时,它不会重定向,但会接收数据。我希望我能正确解释这一点。
有任何想法吗?
<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>