我们遇到了一个奇怪的情况。我们正在调用 a database.transaction(txCallback, txError, txSuccess)
,如果我们在事务调用之后调用一个alert()
调用,txSuccess
则调用该函数而不会调用该
txCallback
函数。
这是一个已知错误,还是有合理解释的记录行为?
它似乎只出现在 Ripple Emulator 和 Google Chrome(Ripple 所基于)中。它不会出现在 Safari 中,无论是使用alert
还是console.log
.
这个 HTML 很好地说明了这种情况:
<html>
<head>
<script>
function dbalert() {
var db = window.openDatabase("test","1.0","test",1024*1024);
console.log("Next line should read: In transaction callback");
window.transactionCalled = false;
db.transaction(
function (tx) {
console.log("In transaction callback");
window.transactionCalled = true;
},
function (tx, err) {
console.error("ERROR");
console.log(err);
},
function () {
if (window.transactionCalled) {
console.log("Success callback: everything worked!");
} else {
console.error("Success callback: BUT TRANSACTION WAS NEVER CALLED");
}
}
);
/*****
* Change to FALSE to get this working.
*****/
if (true) {
alert("Ok, let's see what happened");
} else {
console.log("Ok, let's see what happened");
}
}
</script>
</head>
<body onLoad="dbalert();">
<div id="out">
</div>
</body>
</html>