6

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

Community
  • 1
  • 1
symcbean
  • 47,736
  • 6
  • 59
  • 94
  • you need to reference it with `.find('loaded_dom')` – karthikr Jun 06 '13 at 00:04
  • any error in the browser console – Arun P Johny Jun 06 '13 at 00:42
  • 1
    Which version of jQuery are you using? Firefox 11 is now 10 versions out of date and Chrome 16 is 11 versions out. Not sure if this would be the cause if the issue, but if you're using jQuery 2.x it might be worth giving 1.x a shot just in case. – Sean Powell Jun 06 '13 at 00:50
  • @uncollected: sorry, I should have said - updated question (1.9.1) – symcbean Jun 06 '13 at 09:26
  • @karthikr: I've not seen any reference to using find() after getScript() and am struggling to see how it would help (and why the difference between Chrome and FF) - can you provide an URLs where this is described? – symcbean Jun 06 '13 at 09:29
  • 1
    @symcbean It might be worth using `.done(...)` and `.fail(...)` described [here](http://api.jquery.com/jQuery.getScript/). It looks like an exception object is passed to fail, and that might give more info as to what is going wrong. – Sean Powell Jun 06 '13 at 10:55

1 Answers1

2

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.

symcbean
  • 47,736
  • 6
  • 59
  • 94