使用文本输入字段jQuery将数据推送到Firebase

时间:2017-05-02 05:55:52

标签: javascript jquery firebase firebase-realtime-database

我只是在学习FireBase,并且一直坚持这个问题。我希望用户在输入字段中输入字符串按提交,并将该数据发送到FireBase。任何形式的帮助都会很棒!

由于

    <!DOCTYPE html>
    <html lang="en">
     <head>
     <script 
     src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js">
     </script>
     <script src="https://www.gstatic.com/firebasejs/3.9.0/firebase.js">
     </script>
     <script>

var config = {
apiKey: "AIzaSyCBUbK2d_H7QF3J8BDBPHAHSGJAGS",
authDomain: "my-project.firebaseapp.com",
databaseURL: "https://my-project.firebaseio.com",
projectId: "my-project",
storageBucket: "my-project.appspot.com",
messagingSenderId: "845405833425"
};

firebase.initializeApp(config);
var database;
 database = firebase.database();

var ingInput;

ingInput = $("#fridge");


var submit = $("#submit");
submit.click(sendIng);

//Sends to firebase
function sendIng(){


    //Makes the object
    var data = {
        ingredients: ingInput.text()
    }
    console.log(data);
    var ref = database.ref("ingredients");
    var ingredients = ing.push(data);


    }

   </script>
  </head>
<div id="ingredients-submit">
    <label>Store this item:</label>
<input type="text" id="fridge">
    <button id="submit">Store</button></div>

0 个答案:

没有答案