Web 数据库 - tx.executeSql 回调并非每次都运行

发布于 2025-01-05 21:52:46 字数 1418 浏览 1 评论 0原文

我有一个使用 jQuery Mobile 构建的 HTML5 网站。

在我的index.htm 页面上我有一个ahref。当我单击该链接时,我运行一个执行 tx.executeSql 的函数,并运行回调方法,然后导航到新页面。

第一次效果很好。

如果我导航到更多页面,然后返回到 index.htm 页面,则单击链接时会运行这些函数,但 tx.executeSql 上的回调永远不会运行。

任何想法将不胜感激。我已经使用了所有不同的机制来调用从 javascript 到 jquery 的函数,但这没有什么区别。

需要明确的是 - 调用的第一个函数是 setFeaturedRecruiter() - 您可以看到下面的代码。我第二次回到这里时,“renderResults”回调函数未运行。

// when we click on the actual featured recruiter link we copy from this table to the featured recruiter table to overwrite its contents
function setFeaturedRecruiter() {
    alert('setFeaturedRecruiter()');
    retrieveActualFeaturedRecruiter();
    return true;
}

function retrieveActualFeaturedRecruiter() {
    alert('retrieveActualFeaturedRecruiter()');
    db.transaction(function (tx) {
    alert('select * from featuredRecruiterActual...');
    tx.executeSql('SELECT * FROM featuredRecruiterActual', [], renderResults, pnetOnError);
    });
}

pnetOnError = function (tx, e) {
    alert('Something unexpected happened: ' + e.message);
}

function renderResults(tx, rs) {
    alert('renderResults()');
    var idNo;
    var name;
    var logo;
    var totalAds;
    for (var i = 0; i < rs.rows.length; i++) {
    r = rs.rows.item(i);
    idNo = r.idNo * 1;
    name = r.name;
    logo = r.logo;
    totalAds = r.totalAds;
    }

    writeToFeaturedRecruiter(idNo, name, logo, totalAds);
}

I have an HTML5 website built using jQuery Mobile.

On my index.htm page I have an ahref. When I click on that link I run a function which does a tx.executeSql and the callback method is run which then navigates to the new page.

The works fine the first time.

If I navigate to more pages and then come back to the index.htm page, the functions are run when the link is clicked, however the callback on the tx.executeSql isn't ever run.

Any ideas would be greatly appreciated. I have used all different mechanisms for calling the functions from javascript to jquery, but it makes no difference.

To be clear - the first function called is setFeaturedRecruiter() - you can see the code below. The second time I come back here the "renderResults" callback function isn't run.

// when we click on the actual featured recruiter link we copy from this table to the featured recruiter table to overwrite its contents
function setFeaturedRecruiter() {
    alert('setFeaturedRecruiter()');
    retrieveActualFeaturedRecruiter();
    return true;
}

function retrieveActualFeaturedRecruiter() {
    alert('retrieveActualFeaturedRecruiter()');
    db.transaction(function (tx) {
    alert('select * from featuredRecruiterActual...');
    tx.executeSql('SELECT * FROM featuredRecruiterActual', [], renderResults, pnetOnError);
    });
}

pnetOnError = function (tx, e) {
    alert('Something unexpected happened: ' + e.message);
}

function renderResults(tx, rs) {
    alert('renderResults()');
    var idNo;
    var name;
    var logo;
    var totalAds;
    for (var i = 0; i < rs.rows.length; i++) {
    r = rs.rows.item(i);
    idNo = r.idNo * 1;
    name = r.name;
    logo = r.logo;
    totalAds = r.totalAds;
    }

    writeToFeaturedRecruiter(idNo, name, logo, totalAds);
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情话已封尘 2025-01-12 21:52:47

我通过在页面之间导航时禁用 ajax 解决了这个问题。这是通过添加到 ahref 标签来完成的:data-ajax="false"。这导致页面正确加载并解决了问题。

I've worked around this problem by disabling ajax when navigating between pages. This was done by adding to the ahref tag: data-ajax="false". This caused the page to load correctly and overcomes the problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文