Javascript Chat does not return function

0

I learned that Firebase is an API that helps to create real-time apps , but following a little I know about JS, I tried to create a chat. I did not understand exactly why I could not return a message.

Below I leave the study code:

<!DOCTYPE html>
<html>
    <head>
        <script src="https://cdn.firebase.com/js/client/1.0.17/firebase.js"></script><scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>

    </head>
<body>

  <div id="mensagens"></div>

  <input type="text" id="nomeusuario" placeholder="digitar nome">
  <input type="text" id="mensagem" placeholder="digitar mensagem">

    <script>
    var APP new Firebase("https://nomedomeuapp.firebaseio.com/");

        $("#mensagem").keypress(function (e) {
            if (e.Keycode == 13) {
                var = msg $("#mensagem").val()
                var = usr $("#nomeusuario").val()
                APP.push({ nomeusuario: usr, mensagem: msg });

                $("#mensagem").val('');

            }
        });

        APP.on('child_added', Function(mostra) {
              var novamensagem = mostra.val()//para receber a mensagem
              carregaMensagem(novamensagem.nomeusuario, novamensagem.mensagem);
        });

        function carregamensagem(nome, mensagem) {
            $('<div/>').text(mensagem)
            .prepend($('<strong/>').text(nome + ': '))
            .apprendTo($('#mensagens'));

            $('#mensagens')[0].scrollTop = $('#mensagens')[0].scrollHeight;
        };
    </script>

</body>
</html>
    
asked by anonymous 29.08.2014 / 15:51

2 answers

2

In addition to what has been said above by Edgar, in the line where it has this:

 APP.on('child_added', Function(mostra)

Switch so the word "function" should be lowercase

APP.on('child_added', function(mostra)
    
29.08.2014 / 18:53
2

I saw some errors:

Change this

var APP new Firebase("https://nomedomeuapp.firebaseio.com/");

so

var APP = new Firebase("https://nomedomeuapp.firebaseio.com/");

Change this

var = msg $("#mensagem").val()
var = usr $("#nomeusuario").val()

so

var msg =  $("#mensagem").val();
var usr = $("#nomeusuario").val();

Change this

APP.on('child_added', Function(mostra) ...

so

APP.on('child_added', function(mostra) ...

The rest is correct as I see it.

    
29.08.2014 / 18:11