账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    是否无法在异步操作中中使用cordova中调用sqlite
    • 2017-09-20 00:00
    • 11
    75
    0

    在一个ionic1项目中,需求要做到离线数据库功能,故使用了cordova中的sqlite插件,数据库中的数据会由首次加载app时请求后台数据获取;
    但这时发现貌似无法在异步操作中调用sqlite操作,比如最简单的定时器:

    $timeout(function(){
        //执行sqlite操作
    },1000);

    此时定时器内部的函数并不会执行,并且报错:

    "InvalidStateError: DOM Exception 11: This transaction is already finalized. Transactions are committed after its success or failure handlers are called. If you are using a Promise to handle callbacks, be aware that implementations following the A+ standard adhere to run-to-completion semantics and so Promise resolution occurs on a subsequent tick and therefore after the transaction commits."

    而之后尝试使用了jq的ajax并将其修改为了同步执行:

    $.ajax({
        data: data,
        url: url,
        type: 'post',
        timeout: 3000,
        async: false,
        success: function(data){
            //执行sqllite操作
        },
        error: function() {
            //error
        }
    })

    此时就不再会报之前的一长串错误并且成功回调能够正常执行;

    但是实际项目中不可能使用这种极有可能阻塞整个app的方法(比如用户信号不佳),请问是否有解决方法能够让sqlite在异步操作中执行?

    0
    打赏
    收藏
    点击回答
    您的回答被采纳后将获得:提问者悬赏的 11 元积分
        全部回答
    • 0
    • 若凡飞刀 普通会员 1楼
      502 Bad Gateway

      502 Bad Gateway


      nginx
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部