Paul's Dev Blog – iGonzo.net

Code not fit for human consumption.

The bane of JavaScript

without comments

So I just spent the last hour wondering why my GMaps implementation was not working on a particularly complex site. More to the point, I was wondering why it was working on the live site, but not on the testing site. That is, until I looked at the live site and saw it wasn’t working there either.

Uh oh.

So I started looking at the usual suspects when my JS isn’t working; forgot a semi-colon, misfiring functions, garden gnomes, etc. I then started looking at various doc-types, versions of jQuery and my GMaps API, even my content-type settings, and nothing was working.

Then it hits my like a lightning bolt: 90% of problems I deal with are from content. Specifically, content that has a lot of strange characters that HTML generally, and javascript in particular, doesn’t at all like. So I go through the dynamically rendered markers for my google maps’ points and find, in the 50 or so points I am rendering, there is one name that has an apostrophe in it.

Grrrrr.

A quick replace function in the code and, low and behold, shit starts working again. To make sure it doesn’t happen again I am now running the content through our nifty illegal characters replace function because, in the future, someone may enter a name or something that has a tilde character in it or something else equally strange.

The point is, boys and girls and others, that if you are dealing with javascript, especially if it is very large and complex javascript, be sure that there are no floating apostrophes out there.

On a side note, I am not against apostrophes  in general. I just believe that languages can do without them. I mean seriously; when was the last time you texted a properly formatted message to someone?

Thats what I thought.

K Thx Bia

L8r

Written by iGonzo

October 26th, 2010 at 1:06 am

Leave a Reply