简体   繁体   中英

JQuery throwing Uncaught TypeError: undefined is not a function on button click

Seemingly out of nowhere, I'm getting an error thrown on every button click action.

This is the error;

Uncaught TypeError: undefined is not a function

jquery-2.0.2.min.js:5

x.event.dispatch

y.handle

Here is the HTML;

<script id="make-your-bet-template" type="text/template">
    <div class="joinGameWrapper">
        <div id="betSummary"></div>
        <div class="info">
            <label for="inputEachBet">How much will you bet?</label>
            <input id="inputEachBet" type="text" />
        </div>
        <div class="info buttons">
            <button id="btnSendBet" class="btn">Commit</button>
        </div>
    </div>
</script>

Here is the JS (the console.log isn't rending either so I feel like the issue might be here);

onSendBet: function () {
   var data = {
       eachBet : $('#inputEachBet').val() || 'anon'
   };

   IO.socket.emit('playerSentBet', data);

   App.myRole = 'Player';
   App.myBid = data.eachBet;
   console.log('hello');
},

Binding the buttons to functions;

    bindEvents: function () {
        // Host
        App.$doc.on('click', '#btnCreateGame', App.Host.onCreateClick);
        App.$doc.on('click', '#btnPlaceBet', App.Host.onPlaceBetClick);
        App.$doc.on('click', '#btnLockGame', App.Host.onLockGame);

        // Player
        App.$doc.on('click', '#btnJoinGame', App.Player.onJoinClick);
        App.$doc.on('click', '#btnStart',App.Player.onPlayerStartClick);
        App.$doc.on('click', '.btnAnswer',App.Player.onPlayerAnswerClick);
        App.$doc.on('click', '#btnPlayerRestart', App.Player.onPlayerRestart);
        App.$doc.on('click', '#btnSendBet', App.Player.onSendBet);
    },

Worked it out. The button breaking it all was #btnSendBet. This was assigned to App.Player.onSendBet, however it needed to be assigned to the host. Updating this has resolved all issues.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM