显示未捕获的错误:无法在cordova项目中调用openDatabase方法

时间:2015-10-14 11:38:31

标签: javascript

当我运行此代码时.it显示错误..未捕获错误:无法调用方法' openDatabase'在cordova项目中未定义.deviceready在五秒钟后没有被解雇

   var db;
 dbcreated="false";

function onDeviceReady() {
document.addEventListener("deviceready",onDeviceReady,false);
db=window.SQLitePlugin.openDatabase({ name: 'Registration.db'});
 db.transaction(populateDB,errorCB, populateDB_success);
 var fname = document.getElementById("firstname").value;
 var lname = document.getElementById("lastname").value;
 var age = document.getElementById("age").value;
 var Dob = document.getElementById("Dob").value;
 var password = document.getElementById("pwd").value;
alert("device ready");
 }
function populateDB(tx) {

 var sql = "CREATE TABLE IF NOT EXISTS Registration ( "
   + "firstName TEXT NOT NULL, " + "lastName TEXT NOT NULL, "
   + "age INTEGER, " + "Dob TEXT NOT NULL, "
   + "password TEXT NOT NULL)";
 tx.executeSql(sql);
 var fname = document.getElementById("firstname").value;
 var lname =  document.getElementById("lastname").value;
 var age = document.getElementById("age").value;
 var uname =document.getElementById("Dob").value;
 var pwrd = document.getElementById("pwd").value;
 tx.executeSql("INSERT INTO Registration (firstname,lastname,age,Dob,password) VALUES ('"+ fname +"','"+ lname +"' , "+ age+", '"+ Dob +"','"+ pwrd +"' )");
 alert("data inserted");
}

function errorCB(tx,error) {

 alert("database error:"+ error);
}

function populateDB_success() {
 dbCreated = true;

 // where you want to move
 alert("Successfully inserted");
  window.location="file:///android_asset/www/login.html";
}

1 个答案:

答案 0 :(得分:0)

这里不是专家,冒着明显的风险,但似乎从window.SQLitePlugin为空的异常表明SQLitePlugin未加载,设置或初始化。你是否错过了插件或没有初始化它?