viernes, 2 de septiembre de 2011

SignalR doesn't work in IE - Internet Explorer.

Typical.

Internet Explorer just keeps biting us web developers in the ass and we have no choice but to find work arounds.

After toying around with SignalR on my MVC3 application, I tested things out in IE 8. Surprise surpise. It didn't work.

When you run your application in Internet Explorer you'll see this dreaded icon on the bottom left.





Click it, and you'll be taken to the error window, showing you what went wrong. Go ahead and tick the little checkbox so that window fires up immediately after any javascript errors. We're trying to find the exact culprit.



Hit refresh and this window will pop up. You can now see what's causing things to go south. It's the signalR.min.js file, line 1, position 161.



Let's open up that file and see what's on that line:

[sourcecode language="javascript"]
if (!t.JSON)
throw"SignalR: No JSON parser found. Please ensure json2.js is referenced before the SignalR.js file if you need to support clients without native JSON parsing support, e.g. IE<8."
[/sourcecode]

The SignalR team bless their heart, great documentation. Simple enough, we need the json2.js library.

Using NuGet search for the json2.js file and install it.



Now let's head over to the area where I'm referencing the signalr.js file, and call json2.js before it, like so:

[sourcecode language="html"]
<!-- Used for SignalR -->
<script src="../../Scripts/json2.min.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.signalR.min.js" type="text/javascript"></script>
[/sourcecode]

And you're done. Hit the refresh button on IE and you're asynchronous voodoo will work without a hitch. Thoughts, suggestions for improvement? Leave me a comment.

3 comentarios: