[英]Getting Uncaught Error: Reference.set failed: First argument contains undefined in property when trying to save the data to firebase storage
I have an input field which on entering the input and clicking the save button, the data should be saved in the firebase storage.我有一个输入字段,在输入输入并单击保存按钮时,数据应保存在 firebase 存储中。 The code is as below,
代码如下,
<div class="md-form">
<input type="number" id="ip1" class="form-control">
<label for="ip1">ip1</label>
</div>
<button type="button" id="ip1_btn" class="btn btn-dark-green">SAVE</button>
Below is what I am trying to achieve using js,以下是我尝试使用 js 实现的目标,
var rootRef = firebase.database().ref().child('demo-260b2');
$('#ip1_btn').click(function(){
rootRef.set({
ip1:$('ip1').val()
});
})
While trying on the browser, I am getting the following error,在浏览器上尝试时,我收到以下错误,
Uncaught Error: Reference.set failed: First argument contains undefined in property 'demo-260b2.ip1'
未捕获的错误:Reference.set 失败:第一个参数在属性“demo-260b2.ip1”中包含未定义
I am unable to figure out what's wrong in this.我无法弄清楚这有什么问题。 Any help would be very much helpful.
任何帮助都会非常有帮助。
The error message is telling you that you provided a value of undefined
somewhere in the object to set.错误消息告诉您,您在要设置的对象中某处提供了
undefined
值。 The only value you have here is from $('ip1').val()
.您在此处拥有的唯一值来自
$('ip1').val()
。 I would conclude that value is actually undefined.我会得出结论,价值实际上是未定义的。 You should log/debug it to see for yourself.
您应该记录/调试它以亲自查看。
My guess is that you meant to use this instead: $('#ip1').val()
.我的猜测是您打算改用它:
$('#ip1').val()
。 Note the #
in front of "ip1", which would call out the element with the HTML id "ip1".注意“ip1”前面的
#
,它会调用HTML id 为“ip1”的元素。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.