我正在编写cordova应用程序的代码,以便在函数调用时从Web SQL DB表中删除所有数据。
这是代码
function removeitem(){
db.transaction(function (tx) {
tx.executeSql("DELETE FROM hist", [], function (tx, result) {
toast('Deleted');
}, function (error) {
alert(error.code);
});
}, function (error) {
alert(error);
});
}
但代码不起作用,总是提醒
[对象SQLError]
用于创建表,更新记录的其他功能正常工作但删除查询正在创建问题。请帮助大家找出问题所在。
谢谢
只要您想删除表中的所有数据,请尝试以下语句:
TRUNCATE TABLE hist;
tx.executeSql("TRUNCATE TABLE hist",[],
function(tx,results){console.log("Successfully Emptied")},
function(tx,error){console.log("Could not Empty")}
);
要么
tx.executeSql("DELETE FROM hist",[],
function(tx,results){console.log("Successfully Emptied");},
function(tx,error){console.log("Could not Empty");}
);
其中一个必须工作。
完整代码:
var db.transaction(function (tx) {
tx.executeSql("DELETE FROM hist",[],
function(tx,results){
console.error("Successfully Emptied");
},
function(tx,error){
console.error("Error: " + error.message);
}
)
});
我刚才注意到,这是一个愚蠢的错误。我在打电话
烤面包( '删除');
因此尚未定义的功能声明失败了。对不起我的不好,谢谢你的帮助。