Skip to content

Instantly share code, notes, and snippets.

@pipiscrew
Last active August 29, 2015 14:01
Show Gist options
  • Save pipiscrew/0f9c32268f95f4543447 to your computer and use it in GitHub Desktop.
Save pipiscrew/0f9c32268f95f4543447 to your computer and use it in GitHub Desktop.
[js] Firebase - Transaction update multiple fields
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
<script type='text/javascript' src='jquery-1.10.2.min.js'></script>
<!-- firebase -->
<script type='text/javascript' src='https://cdn.firebase.com/v0/firebase.js'></script>
<script type='text/javascript' src='https://cdn.firebase.com/v0/firebase-simple-login.js'></script>
<script type="text/javascript">
$(function() {
$('#btn').on('click', function(e) {
var db = new Firebase('https://x.firebaseio.com/mynode/-JFXdllZKp2AE9uJOZlN/stats');
db.transaction(function(rec) {
// If test1 or test2 has never been set, will be setted!
if (rec!=null){
rec["test1"]="pipiscrew";
rec["test2"]=1;
}
return rec;
}, function(error, committed, snapshot) {
if (committed){
mae2(cause_id,3);
}
});
});
});
</script>
</head>
<body>
<button id="btn">Push Me</button>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment