の両方で動作するように以下のコードを取得します。どんな助けでも大歓迎です。これはSafariで動作しますが、いないクロムに理由を把握することができないようChromeとSafariの
//Create or use existing DB
var db = openDatabase('myTest', '1.0', 'mySpecialDatabase', 200000);
if (db) {
//New Transaction
db.transaction(function (tx) {
tx.executeSql('DROP TABLE IF EXISTS foo');
tx.executeSql('CREATE TABLE IF NOT EXISTS foo (id unique, text)');
//Insert test data
tx.executeSql('INSERT INTO foo (id, text) VALUES (1, "myTest")');
tx.executeSql('INSERT INTO foo (id, text) VALUES (2, "another")');
tx.executeSql('INSERT INTO foo (id, text) VALUES (3, "andYetAnother")');
tx.executeSql('INSERT INTO foo (id, text) VALUES (4, "ohAndAgain")');
});
alert("DB success");
}
else {
alert("Oooops");
}
db.transaction(function (tx) {
// Loop rows of DB, print values
tx.executeSql('SELECT * FROM foo',[], function (tx, results) {
var rows = results.rows;
alert(rows.length);
for (var index = 0; index < rows.length; index++) {
var x = rows.item(index);
alert(x.text);
}
});
});
、いずれかのブラウザでJSFiddleでそれを投げるのSafariの最新版が、クロムではありません、このような幸運に意図したとおりに動作します。
EDITは、私はそれが最後で働いて得ることができた - 以下のコードは見ることができます。
var db = openDatabase('CBDB', '1.0', 'mySpecialDatabaseThatWontWork',10*1024*1024);
db.transaction(function (tx){
tx.executeSql('DROP TABLE IF EXISTS cb');
alert("dropped table");
createDB();
queryDB();
},
function (tx, error) {
// error
alert('0.Something went wrong: '+ error.message);
});
function createDB(){
db.transaction(function (tx) {
tx.executeSql('CREATE TABLE IF NOT EXISTS cb (id unique, text)');
tx.executeSql('INSERT INTO cb (id, text) VALUES (1, "myTest")');
tx.executeSql('INSERT INTO cb (id, text) VALUES (2, "another")');
tx.executeSql('INSERT INTO cb (id, text) VALUES (3, "andYetAnother")');
tx.executeSql('INSERT INTO cb (id, text) VALUES (4, "ohAndAgain")');
alert("DB success");
},
function (tx, error) {
// error
alert('1.Something went wrong: '+ error.message);
});
}
function queryDB(){
db.transaction(function (tx) {
tx.executeSql('SELECT * FROM cb',[], function (tx, results) {
var rows = results.rows;
alert(rows.length);
for (var index = 0; index < rows.length; index++) {
var x = rows.item(index);
alert(x.text);
}
},
function (tx, error) {
// error
alert('2.Something went wrong: '+ error.message);
});
});
}
ねえ男!素敵な仕事、ええ、私は最後にそこに着いた。しかし、これをありがとう。 – Julio