将 Web sql 结果显示为 html
我已经使用 sqlite 创建了一个 Web sql,以使用 javascript 创建数据库,我希望将结果显示到列表项标记内的另一个 html 页面上。我怎样才能实现这个目标?我在开发移动应用程序时使用 jquery 和phonegap。
// Populate the database
//
function populateDB(tx) {
tx.executeSql('DROP TABLE IF EXISTS DEMO');
tx.executeSql('CREATE TABLE IF NOT EXISTS DEMO (id unique, data)');
tx.executeSql('INSERT INTO DEMO (id, data) VALUES (1, "First row")');
tx.executeSql('INSERT INTO DEMO (id, data) VALUES (2, "Second row")');
}
// Query the database
//
function queryDB(tx) {
tx.executeSql('SELECT * FROM DEMO', [], querySuccess, errorCB);
}
// Query the success callback
//
function querySuccess(tx, results) {
var len = results.rows.length;
console.log("DEMO table: " + len + " rows found.");
for (var i=0; i<len; i++){
console.log("Row = " + i + " ID = " + results.rows.item(i).id + " Data = " + results.rows.item(i).data);
//the data from here to the html page.
}
}
// Transaction error callback
//
function errorCB(err) {
console.log("Error processing SQL: "+err.code);
}
// Transaction success callback
//
function successCB() {
var db = window.openDatabase("Database", "1.0", "PhoneGap Demo", 200000);
db.transaction(queryDB, errorCB);
}
html页面:
<div data-role="content" class="ui-content" role="main">
<div id="wrapper" >
<div id="scroller" >
<ul data-role="listview" data-theme="c" class="ui-btn-inset">
<li>would like to put it inside here</li>
</ul>
</div>
</div>
是否可以包含一个链接?还需要 Ajax 吗?
谢谢。
I have created a web sql using sqlite to create a database using javascript and I want the results to be displayed onto another html page inside the list items tag. How can I achieve this? I am using jquery and phonegap as I am developing a mobile app.
// Populate the database
//
function populateDB(tx) {
tx.executeSql('DROP TABLE IF EXISTS DEMO');
tx.executeSql('CREATE TABLE IF NOT EXISTS DEMO (id unique, data)');
tx.executeSql('INSERT INTO DEMO (id, data) VALUES (1, "First row")');
tx.executeSql('INSERT INTO DEMO (id, data) VALUES (2, "Second row")');
}
// Query the database
//
function queryDB(tx) {
tx.executeSql('SELECT * FROM DEMO', [], querySuccess, errorCB);
}
// Query the success callback
//
function querySuccess(tx, results) {
var len = results.rows.length;
console.log("DEMO table: " + len + " rows found.");
for (var i=0; i<len; i++){
console.log("Row = " + i + " ID = " + results.rows.item(i).id + " Data = " + results.rows.item(i).data);
//the data from here to the html page.
}
}
// Transaction error callback
//
function errorCB(err) {
console.log("Error processing SQL: "+err.code);
}
// Transaction success callback
//
function successCB() {
var db = window.openDatabase("Database", "1.0", "PhoneGap Demo", 200000);
db.transaction(queryDB, errorCB);
}
html page:
<div data-role="content" class="ui-content" role="main">
<div id="wrapper" >
<div id="scroller" >
<ul data-role="listview" data-theme="c" class="ui-btn-inset">
<li>would like to put it inside here</li>
</ul>
</div>
</div>
Is it possible to include a link with it? Also is Ajax needed for this?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一个快速解决方案。您只需将 LI 标签附加到 UL 的内部 HTML 中即可。
Here's a quick solution. You just append LI tags to the inner HTML of the UL.
这是一个简化的示例:
Here is a simplified example: