无法从phonegap应用程序中的web sql数据库检索数据
我正在 iOS 上开发一个phonegap应用程序,需要存储一些数据。我正在使用phonegap 文档中给出的存储API,并且我相信数据正在被插入。但是当我尝试使用 SELECT 语句检索数据时,我没有在警报框中得到任何输出。
正在显示“loading2”警报,但之后我没有得到任何输出。
我的代码如下(摘自phonegap wiki):
// load the currently selected icons
function loadCelebs(mydb)
{
try
{
alert("loading2");
mydb.transaction(
function(transaction)
{
transaction.executeSql('SELECT * FROM celebs ORDER BY name', [], celebsDataHandler(transaction,results));
});
}
catch(e)
{
alert(e.message);
}
}
// callback function to retrieve the data from the prefs table
function celebsDataHandler(tx, results)
{
// Handle the results
alert(results);
}
I am working on a phonegap app on iOS that needs to store some data. I am using the storage API given in phonegap docs and I believe the data is being inserted. But when I am trying to retrieve the data using SELECT statement, I am not getting any output in the alert boxes.
the "loading2" alert is being shown but after that i dont get any output.
My code is as below (picked up from phonegap wiki):
// load the currently selected icons
function loadCelebs(mydb)
{
try
{
alert("loading2");
mydb.transaction(
function(transaction)
{
transaction.executeSql('SELECT * FROM celebs ORDER BY name', [], celebsDataHandler(transaction,results));
});
}
catch(e)
{
alert(e.message);
}
}
// callback function to retrieve the data from the prefs table
function celebsDataHandler(tx, results)
{
// Handle the results
alert(results);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试将其更改为:
您不希望 transaction() 调用中包含 (tx, results) 部分。您只需传递对回调处理程序的引用,以便它可以在完成后运行它。通过添加 (tx, results),您正在执行并传递结果。
另外,请考虑传递错误处理程序。如果您知道错误是什么,则可以使调试变得更容易。
Try changing it to:
You don't want the (tx, results) part in the transaction() call. You are only passing a reference to the callback handler so that it can run it when it is done. By adding the (tx, results) you are executing and passing in the result.
Also, consider passing in an error handler. It can make debugging easier if you know what the errors are.