aspnet / SignalR-samples

Samples for ASP.NET Core SignalR

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Uncaught TypeError in ChatSample

robcube opened this issue · comments

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);

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);

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