Это потому, что ваша функция uniqueId()
неверна.Вы можете увидеть это, имея кнопку на своей странице со следующим кодом:
<input
id="clickMe"
type="button"
value="clickme"
onclick="console.log(uniqueId());"
/>
Так что если вы измените свою функцию на что-то вроде следующего, она будет работать:
var counter = 0;
function uniqueId() {
return 'myid-' + counter++;
}
function writeUserData(title, content, postID) {
firebase.database().ref('posts/' + postID).set({
title: title,
content: content
});
}
......
<button onclick="writeUserData(document.getElementById('blog-title').value, document.getElementById('blog-content').value, uniqueId())">Add</button>
Обратите внимание, что вы можете разрешить Firebase генерировать UniqueIds, см. https://firebase.google.com/docs/reference/js/firebase.database.Reference#push