Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/395.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用用户设置创建PhoneGap SQL Lite数据库_Javascript_Sql_Database_Cordova - Fatal编程技术网

Javascript 使用用户设置创建PhoneGap SQL Lite数据库

Javascript 使用用户设置创建PhoneGap SQL Lite数据库,javascript,sql,database,cordova,Javascript,Sql,Database,Cordova,我正在尝试创建我的第一个针对iOS的phonegap应用程序。 这个应用程序的用途很简单,但是我在SQLLite数据库中遇到了一些错误。 目标只是将用户的一些设置保存到数据库中,然后根据这些设置显示一些常规统计信息。 因此,应用程序应该能够插入/更新用户设置性别、县、年龄。 DB最终应该是一个全局数据库,包含所有用户输入,然后显示基于此的统计数据——但对于im制作的原型,本地数据库是可以的 从在线教程中创建/插入/更新/选择数据库的代码对我来说很好,但实际上什么也没发生。我甚至不确定数据库是否真

我正在尝试创建我的第一个针对iOS的phonegap应用程序。 这个应用程序的用途很简单,但是我在SQLLite数据库中遇到了一些错误。 目标只是将用户的一些设置保存到数据库中,然后根据这些设置显示一些常规统计信息。 因此,应用程序应该能够插入/更新用户设置性别、县、年龄。 DB最终应该是一个全局数据库,包含所有用户输入,然后显示基于此的统计数据——但对于im制作的原型,本地数据库是可以的

从在线教程中创建/插入/更新/选择数据库的代码对我来说很好,但实际上什么也没发生。我甚至不确定数据库是否真的被创建了,这应该是根据phonegap文档创建的

//脚本代码//

var db; 
var shortName = 'WebSqlDB'; 
var version = '1.0'; 
var displayName = 'WebSqlDB'; 
var maxSize = 200000;

function onDeviceReady() {
    var db = window.openDatabase(shortName, version, displayName, maxSize); 
}

function errorHandler(transaction, error) { 
    alert('Error: ' + error.message + ' code: ' + error.code); 
}

function successCallBack() { 
    alert("DEBUGGING: success"); 
}

init(){
    alert("DEBUGGING: we are in the onBodyLoad() function");
    if (!window.openDatabase) {
        alert('Databases are not supported in this browser.'); 
        return;
    }
    db.transaction(function(tx){
        tx.executeSql( 'CREATE TABLE IF NOT EXISTS User(UserId INTEGER NOT 
    NULL PRIMARY KEY, County TEXT NOT NULL, Gender TEXT NOT NULL, Age INTEGER NOT NULL)', [],nullHandler,errorHandler); 
    },errorHandler,successCallBack);
        }
    $('#lbUsers').html('');
    db.transaction(function(transaction) { 
       transaction.executeSql('SELECT * FROM User;', [], 
         function(transaction, result) { 
          if (result != null && result.rows != null) { 
            for (var i = 0; i < result.rows.length; i++) { 
              var row = result.rows.item(i); 
              $('#lbUsers').append('<br>' + row.UserId + '. ' + 
    row.County + ' ' + row.Gender + ' ' + row.Age); 
            } 
          } 
         },errorHandler); 
     },errorHandler,nullHandler);
   return; 
}

function AddValueToDB() { 
    if (!window.openDatabase) { 
       alert('Databases are not supported in this browser.'); 
       return; 
     }
    db.transaction(function(transaction) { 
       transaction.executeSql('INSERT INTO User(County, Gender, Age) 
    VALUES (?,?,?)',[$('#txCounty').val(), $('#txGender').val(), $('#txAge').val()], 
         nullHandler,errorHandler); 
       });
    ListDBValues(); 

     return false; 
}
//HTML代码//

<form>
    <label for="county">County:</label>
    <input id="txCounty" type="text" name="county" id="county" value="" placeholder="County" />
    <fieldset data-role="controlgroup" data-type="horizontal">
    <legend>Gender:</legend>
    <input type="radio" name="radio-choice-h-2" id="radio-choice-h-2a" value="male" checked="checked">
    <label for="radio-choice-h-2a">Male</label>
    <input type="radio" name="radio-choice-h-2" id="radio-choice-h-2b" value="female">
    <label for="radio-choice-h-2b">Female</label>
    </fieldset>
    <label for="age">Age:</label>
    <input type="number" name="age" id="txAge" value="" placeholder="Age" />
    <input type="button" value="Add record" onClick="AddValueToDB()">
    <input type="button" value="Refresh" onClick="ListDBValues()">
</form>
<span style="font-weight:bold;">Currently stored values:</span> 
<span id="lbUsers"></span>
在控制台中,它表示“未定义ListDBValues、AddValueToDB和init”。 我知道我把它当作我的助理。。
我真的需要一些指导!非常感谢

使用lint检查javascript:

phonegap js以静默方式失败,lint可以帮助调试代码

$ jsl process yourcode.js