Search code examples
jquerysignalrjquery-3

Error code in jquery-3.0.0.min.js


I'm not sure it's an error, but when I tried to change the version 3.0.0 to version 2.2.3, it's working fine.

I'm making a demo with signalr, like this:

In the html:

<button>Click me</button>
// <script src="https://code.jquery.com/jquery-3.0.0.min.js"></script>
<script src="https://code.jquery.com/jquery-2.2.3.min.js"></script>
<script src="~/scripts/jquery.signalR-2.2.0.js"></script>
<script src="~/signalr/hubs"></script>
<script src="~/scripts/app.js"></script>

In app.js:

var hub = $.connection.hub;
var chat = $.connection.chat;

hub.start().done(function () {
    $('button').click(function () {
        chat.server.sayHello('Hermione').done(function (msg) {
            alert(msg)
        });
    });
});

In the Hub:

public string SayHello(string name)
{
    return "Hello " + name;
}

Here is the error snapshot when I tried to use jquery version 3.0.0:

1

Error messages:

Uncaught TypeError: a.indexOf is not a function

Uncaught Error: SignalR: SignalR is not loaded. Please ensure jquery.signalR-x.js is referenced before ~/signalr/js.

My question: what's happen with the jquery version 3.0.0 in this case?


Solution

  • If you are using the SignalR plug-in, jQuery v3.0.0 is apparently unsupported. The plug-in documentation does not seem to provide any information about dependencies but examples in wiki load jQuery 1.7.

    You simply cannot blame the jQuery team for that: they provide detailed release notes, migration guides and even a helper plugin. If you aren't sure that your code will work with newer releases, you shouldn't upgrade :-)