わかりました、いくつかのコードを機能させようとして遊んでいますが、現在のセットアップではあまり運がありませんが、それを変更する方法もわかりません...
私が得ているエラーは次のとおりです。
それで、データを追加するまでにデータ接続が利用できないと思いますか?
どんな助け、ポインタも大歓迎です!
var WebSqlStore = function(successCallback, errorCallback) {
var eventsURL='http://www.url.com/api/eventsWEBSQL.php';
this.initializeDatabase = function(successCallback, errorCallback) {
var self = this;
this.db = window.openDatabase("AADB", "1.0", "App DB", 200000);
this.db.transaction(
function(tx) {
self.createEvents(tx);
self.addEvents(tx);
},
function(error) {
console.log('Transaction error: ' + error);
if (errorCallback) errorCallback();
},
function() {
console.log('Transaction success');
if (successCallback) successCallback();
}
)
}
this.createEvents = function(tx) {
tx.executeSql('DROP TABLE IF EXISTS events');
var sql = "CREATE TABLE IF NOT EXISTS events ( " +
"id INTEGER PRIMARY KEY AUTOINCREMENT, " +
"userid INTEGER, " +
"name VARCHAR(255), " +
"subname VARCHAR(255), " +
"startdate DATETIME, " +
"duration VARCHAR(255), " +
"location VARCHAR(100), " +
"address VARCHAR(255), " +
"city VARCHAR(255), " +
"county VARCHAR(255), " +
"postcode VARCHAR(15), " +
"telephone VARCHAR(20), " +
"modules VARCHAR(255), " +
"description TEXT, " +
"feedback TEXT, " +
"archive INTEGER, " +
"live INTEGER" +
")";
tx.executeSql(sql, null,
function() {
console.log('Create table success');
},
function(tx, error) {
alert('Create table error: ' + error.message);
});
}
this.addEvents = function(tx) {
$.ajax({
type: "GET",
url: eventsURL,
dataType: 'jsonp',
data: { LN: 0 },
success:function (data) {
var events = data
var l = events.length;
//console.log("Events length: "+l);
var sql = "INSERT OR REPLACE INTO events " +
"(id, userid, name, subname, startdate, duration, location, address, city, county, postcode, telephone, modules, description, feedback, archive, live) " + //16
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
var e;
for (var i = 0; i < l; i++) {
e = events[i];
tx.executeSql(sql, [e.id, e.userid, e.name, e.subname, e.startdate, e.duration, e.location, e.address, e.city, e.county, e.postcode, e.telephone, e.modules, e.description, e.feedback, e.archive, e.live],
function() {
console.log('INSERT success');
},
function(tx, error) {
alert('INSERT error: ' + error.message);
}
);
}
},
error:function(error) {
app.showAlert("Internet access is required to get new items, Will continue using local data ", "Events");
console.log(error);
}
});
} //End addEvents
this.initializeDatabase(successCallback, errorCallback);
}