Firebase update callback for error detection and success

How do I make this callback? I read the docs, but I just can't figure it out for some reason?

var ref = new Firebase("https://xxx.firebaseio.com/public/"+$scope.uid+"/shows/"); var blast = ref.child(show_title); blast.update({ "show_title": show_title, "show_image": show_image, "show_description": show_description, "show_email": show_email, "time": Firebase.ServerValue.TIMESTAMP }); blast.update("I'm writing data", function(error) { if (error) { alert("Data could not be saved." + error); } else { alert("Data saved successfully."); } }); 
+7
firebase
source share
2 answers

Frank's solution is perfect for your question. Another option is to use an update promise. This is especially useful if you are doing a bunch of operations, which is often the case with Firebase.

here is an example using promise

 blast.update({ update: "I'm writing data" }).then(function(){ alert("Data saved successfully."); }).catch(function(error) { alert("Data could not be saved." + error); }); 
+9
source share

The second update() call causes this error in the JavaScript console:

Unfixed error: Firebase.update failed: the first argument should be an object containing replaced children. (...)

The first argument to update must be an object, therefore:

 blast.update({ update: "I'm writing data" }, function(error) { if (error) { alert("Data could not be saved." + error); } else { alert("Data saved successfully."); } }); 

For reference, this is the documentation for the update() function .

+7
source share

All Articles