aspnet / SignalR-samples

Samples for ASP.NET Core SignalR
750 stars 398 forks source link

Uncaught TypeError in ChatSample #28

Closed robcube closed 6 years ago

robcube commented 6 years ago

Using Windows 7, latest Chrome, latest SDK; preview-2

Pulled it down via github, ran as is. However, "url" should be replaced with "/chat" in index.html.

(index):55 Uncaught TypeError: Cannot read property 'invoke' of undefined at HTMLInputElement. ((index):55)

at line connection.invoke('send', name, messageInput.value);

robcube commented 6 years ago

This works:

Change the javascript piece in index.html from:

            // Transport fallback functionality is now built into start.
            connection.start()
                .then(function (connection) {
                    console.log('connection started');
                    document.getElementById('sendmessage').addEventListener('click', function (event) {
                        // Call the Send method on the hub.
                        connection.invoke('send', name, messageInput.value);

                        // Clear text box and reset focus for next comment.
                        messageInput.value = '';
                        messageInput.focus();
                        event.preventDefault();
                    });
            })
            .catch(error => {
                console.error(error.message);
            });

to:

            document.getElementById('sendmessage').addEventListener('click', function (event) {
                // Call the Send method on the hub.
                connection.invoke('send', name, messageInput.value);

                // Clear text box and reset focus for next comment.
                messageInput.value = '';
                messageInput.focus();
                event.preventDefault();
            });

            connection.start().catch(err => console.error);
kmorcinek commented 6 years ago

IMHO it should be reopen cause PR has not been merged so far.