Tuesday, February 21, 2012

Trouble with the jQuery-tmpl plugin

I used the jquery-tmpl plugin extensively on the Docphin website.  It is a great tool and allowed me to do some  things without all the normal asp.net web form bloat.  However, there was one small (make that large) problem.  The site didn't work from inside any VA hospital.  Well, the site worked but the parts of the site that relied on the jquery tmpl plugin didn't work and it just so happened that most of the content of the site relied on it.  No good.

It was baffling.  The site worked fine across all browsers but at two different VA hospitals, the site would fail when it tried to apply the jquery template to the returned data context.  I could see through firebug that the data had returned and that it was correct, but when it hit the .appendTo method I would get:

Object doesn’t support this property or method

Drove me crazy.  I setup a demo page that did a very simple call to the plugin, but that didn't work either.  I tried updating my jQuery include thinking that maybe there was something about an older version that didn't work well.  I'd read on Boris Moore's blog (he's the author of the plugin) that tmpl was being depreciated and that JsView and JsRender were taking over.  I wrote demo pages for those newer plugins as well.  They all worked fine except at the VA.  They all returned the same error those locations.

I tried a few other things but I decided to work on something else and come back to the problem later.  One of those other things was to give the docphin website an SSL certificate.  I installed it and made sure everything on the pages were calling outside resources through SSL so that I wouldn't get those annoying "not everything on the page is encrypted" notifications.  Once that was set, I had someone test the site again from the VA hospital, just to see if SSL made any difference.  It did.  No more problems. The tmpl worked fine.

So my guess is that the network security rules at the VA hospitals prevents non encrypted ajax calls that make use of non standard script types(in this case the type="text/x-jquery-tmpl).  That's a mouthful, but that appears to be it.  I haven't tried it with JsView and JsRender yet, but I assume it will work.

So, if you are using the jQuery tmpl plugin on a website and it keeps failing on the .appendTo() method at a specific location but it works everywhere else, try making the site SSL.  It works if you are at the VA.