symcbean
symcbean

Reputation: 48367

jQuery getScript issue

While it seems like lots of people seem to hav been having trouble with this on Stack Overflow, I've yet see a description of why it was going wrong (1, 2, 3)

My code (for testing purposes):

jQuery.getScript("res/fader.js", function () { alert("loaded"); });

works flawlessly in Chrome (16). In Firefox (11) the firebug console shows the script being requested and the expected response (including the mimetype of application/javascript). But no alert. No error. Nothing.

If I subsequently try to reference something in the script which should have been loaded, it is still undefined (this is several seconds after the onload event and after the console shows the script has been retrieved).

update

I'm using jQuery 1.9.1

Upvotes: 6

Views: 1935

Answers (1)

symcbean
symcbean

Reputation: 48367

Kudos and thanks to uncollected (add an answer & I'll mark it as accepted) adding the exception hander, I found the problem...

An exception was occurring - which was being handled silently by jQuery. Adding the handler via getScript() revealed the problem was "invalid assignment left-hand side". Unfortunately this exception doesn't say where the error occurred. I then tried a different method of loading the script (creating a script element and appending it to the body) which meant that the default handler in the browser was triggered which gave me the line number and the bit of offending code:

this=null;

This is intended to clean up the object instance, to avoid a memory leak and works in Chrome, but not in Firefox.

Upvotes: 2

Related Questions