Javascript 输入数据后,重定向到其他页面

Javascript 输入数据后,重定向到其他页面,javascript,jquery,html,cordova,Javascript,Jquery,Html,Cordova,在提交详细信息后,我试图重定向到另一个页面。 我已经尝试了注释掉的代码。它确实是直接的,但不接收数据。 当我将注释取出时,它不会重定向,但会接收数据。 我希望我正确地解释了这一点 有什么想法吗 <script> var curatio = {}; curatio.webdb = {}; curatio.webdb.db = null; curatio.webdb.open = function() {

在提交详细信息后,我试图重定向到另一个页面。 我已经尝试了注释掉的代码。它确实是直接的,但不接收数据。 当我将注释取出时,它不会重定向,但会接收数据。 我希望我正确地解释了这一点

有什么想法吗

      <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>&nbsp;&nbsp;&nbsp;&nbsp;Weight:&nbsp;" + row.todo  + "&nbsp;kg&nbsp;" + "<br />" + "&nbsp;&nbsp;&nbsp;&nbsp;Date:&nbsp;" + row.date + "<br />" + "&nbsp;&nbsp;&nbsp;&nbsp;Note:&nbsp;" + row.note + "&nbsp;&nbsp;&nbsp;&nbsp;[<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>

var curatio={};
curatio.webdb={};
curatio.webdb.db=null;
curatio.webdb.open=函数(){
var dbSize=5*1024*1024;//5MB
curatio.webdb.db=openDatabase(“curatio”、“1.0”、“Todo管理器”、dbSize);
}
curatio.webdb.createTable=函数(){
var db=curatio.webdb.db;
数据库事务(功能(tx){
tx.executeSql(“如果不存在,则创建表权重(ID整数主键ASC、todo文本、添加的日期时间、日期文本、注释文本)”,[];
});
}
curatio.webdb.addTodo=函数(todoText){
var db=curatio.webdb.db;
数据库事务(功能(tx){
var addedOn=新日期();
var date=document.getElementById(“日期”).value;
var note=document.getElementById(“note”).value;
tx.executeSql(“插入重量(todo,添加日期,注释)值(?,,?)”,
[todoText,ADEDON,日期,注释],
curatio.webdb.onSuccess,
curatio.webdb.onError);
});
}
curatio.webdb.onError=函数(tx,e){
警报(“出现错误:+e.message”);
}
curatio.webdb.onSuccess=函数(tx,r){
//重新呈现数据。
curatio.webdb.getAllTodoItems(loadTodoItems);
}
curatio.webdb.getAllTodoItems=函数(renderFunc){
var db=curatio.webdb.db;
数据库事务(功能(tx){
tx.executeSql(“从权重中选择*”,[],renderFunc,
curatio.webdb.onError);
});
}
curatio.webdb.deleteTodo=函数(id){
var db=curatio.webdb.db;
数据库事务(功能(tx){
tx.executeSql(“从权重中删除,其中ID=?”,[ID],
curatio.webdb.onSuccess,
curatio.webdb.onError);
});
}
功能加载到DoItems(tx、rs){
var rowOutput=“”;
var todoItems=document.getElementById(“todoItems”);
对于(变量i=0;i重量:“+row.todo+”kg“+”
“+”日期:“+row.Date+”
“+”注释:“+row.Note+”[]”; } 函数init(){ curatio.webdb.open(); curatio.webdb.createTable(); curatio.webdb.getAllTodoItems(loadTodoItems); } 函数addTodo(){ var todo=document.getElementById(“todo”); curatio.webdb.addTodo(todo.value); todo.value=“”; 警惕(“您的体重已增加”); //window.location='users.html' //location.href=“users.html”; }
。。。


重量
日期
笔记

http是无状态的,您必须使用查询字符串将参数带到其他页面 例如 window.location.href=“users.html?myVlue=9” 然后在另一个页面中处理myvalue


我希望这有帮助

更改您的onsubmit以返回函数而不是false…然后在JS函数中简单地返回false以停止提交表单,或返回true以正常提交表单。这里有一个简短的例子来说明我的意思

<script>
    function validateForm(){
        var x=document.forms["myForm"]["fname"].value;
        if (x==null || x==""){
            alert("First name must be filled out");
            return false;
        }
    }
</script>

<form name="myForm" action="demo_form.asp" onsubmit="return validateForm()" method="post">
    First name: <input type="text" name="fname">
    <input type="submit" value="Submit">
</form>

函数validateForm(){
var x=document.forms[“myForm”][“fname”].value;
如果(x==null | | x==“”){
警告(“必须填写姓名”);
返回false;
}
}
名字:

您可以尝试
window.opener
将数据从一页发送到另一页。尽管这将在新窗口中打开页面。这上面有很多页面,请尝试用谷歌搜索
window.opener
。 一定要让我知道这是否适合你。

我找到了一个工作! 给数据库一两秒钟的更新时间,然后重定向 这对我很有用:

function addTodo() {
    var todo = document.getElementById("todo");
    curatio.webdb.addTodo(todo.value);
    todo.value = "";
    alert("Your weight has been added");
    setTimeout(function () {
    window.location.href = "users.html"; //will redirect to your blog page (an ex: blog.html)
    }, 1000);
}

什么是curatio.webdb.addTodo?它有提供回调的选项吗?安迪,我添加了完整的脚本。希望有帮助。我建议你看看。你好,贝舍。抱歉在这件事上有点傻,但你能说得更具体一点吗?我怎么做你的建议?拉扎,你是在建议window.opener.document.location(“users.htm”);不完全是这样,您可以使用
window.opener.variableName=yourVariableWithData
将需要的数据传递到其他页面。在另一个页面中,使用
newVariableForData=window.opener.variableName
此方法非常容易实现。我希望这对你有帮助。仅供参考-这在安卓平板电脑上有效,但在IOS上无效。但在移动设备上似乎不起作用:(我清除了我的移动网络历史记录,它实际上工作得很好!重新加载,现在它工作100%
function addTodo() {
    var todo = document.getElementById("todo");
    curatio.webdb.addTodo(todo.value);
    todo.value = "";
    alert("Your weight has been added");
    setTimeout(function () {
    window.location.href = "users.html"; //will redirect to your blog page (an ex: blog.html)
    }, 1000);
}