javascript - How to return Success data after update in firebase - Stack Overflow

I tried to return data after update in firebase but it is displaying as undefinedtest().then((res) =>

I tried to return data after update in firebase but it is displaying as undefined

    test().then((res) => {
        alert(res);
      });

    test() {
    var fredNameRef = new Firebase('');

    var onComplete = function(error) {
      if (error) {
        return error;
      } else {
        return "success";
      }
    };
    fredNameRef.update({ first: 'Wilma', last: 'Flintstone' }, onComplete);
    }

I tried to return data after update in firebase but it is displaying as undefined

    test().then((res) => {
        alert(res);
      });

    test() {
    var fredNameRef = new Firebase('https://docs-examples.firebaseio./samplechat/users/fred/name');

    var onComplete = function(error) {
      if (error) {
        return error;
      } else {
        return "success";
      }
    };
    fredNameRef.update({ first: 'Wilma', last: 'Flintstone' }, onComplete);
    }
Share Improve this question asked Mar 19, 2016 at 18:46 Akash RaoAkash Rao 9283 gold badges12 silver badges25 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

The onComplete callback is used to check for errors during the update, not to receive the data.

The Firebase SDK surfaces update first locally, and then if successful it fires the onComplete callback.

In your case you want to save the data and then listen for the update using the .on() method.

var fredNameRef = new Firebase('https://docs-examples.firebaseio./samplechat/users/fred/name');

fredNameRef.on('value', function(snap) {
  console.log(snap.val());
});

fredNameRef.update({ first: 'Wilma', last: 'Flintstone' });

After the .update() method is executed, it will trigger the .on() method.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744131186a4559849.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信