1
我有一個插入員工記錄的html表單,在提交記錄時只保存在瀏覽器數據庫即websql上,但它給了我錯誤「無法打開數據庫,版本不匹配」插入第二條記錄時,「1.0」與「'」 的currentVersion不匹配。 請給出建議來解決這個問題。插入第二條記錄時的Web SQL數據庫版本錯誤
以下是我爲它所做的代碼。
function myfunction() {
debugger;
var obj = {};
obj.first_name = $("#txtFirstName").val();
obj.last_name = $("#txtLastName").val();
obj.qualification = $("#txtQualication").val();
obj.age = $("#txtAge").val();
if (typeof (Storage) !== "undefined") {
//websql supported
var localstorage = openDatabase('dbemp', '1.0', 'employess database', 2 * 1024 * 1024, function() {
console.log("created/found database");
});
var success = function() {
$("#txtFirstName").val("");
$("#txtLastName").val("");
$("#txtQualication").val("");
$("#txtAge").val("");
};
var failure = function() {
alert('records don\'t save');
};
localstorage.transaction(function (tx) {
tx.executeSql('CREATE TABLE IF NOT EXISTS employee (first_name, last_name, qualification, age)', function() {
console.log("created table");
}, function() {
tx.executeSql('INSERT INTO employee (first_name, last_name, qualification, age) VALUES (?, ?, ?, ?)',
[obj.first_name, obj.last_name, obj.qualification, obj.age],success,failure);
console.log("Insert record successfully..");
alert('Record Save locally');
});
});
} else {
console.log("NOT SUPPORTED");
}
}