Monday, 9 August 2010

$(Document) is null or not an object

I've just spent a very painful hour or so debugging a jQuery issue that turned out to be a self inflicted problem!  The site I was working on had been working perfectly all morning, then a particular page began to fail on a refresh (browser F5).  It was possible to browse to the page and it displayed correctly, but press F5 to refresh the page and it failed on the statement below.  Checking the contents of document showed it to be populated, but $(document) failed with an error saying it was either null or not an object.

$(document).ready(function() {
   AttachCloseEvents();
});

It just didn't make sense, going to the page everything would work as expected but refreshing the very same page caused it to fail - it didn't matter if it was the start up page of the visual studio project or not.  In one of the many attempts to isolate / identify the problem I cleared out the browser cache.  Amusingly this now broke the entire site - the error occurred every time the page was viewed.

............It was at this point that I noticed I'd accidently moved the projects localised copy of jQuery.  The requests to the page that had worked originally had been using a browser cached copy of the file - it was the refresh of the page that was acting correctly.

No comments:

Post a Comment