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

6
  • you need to reference it with .find('loaded_dom') Commented Jun 6, 2013 at 0:04
  • any error in the browser console Commented Jun 6, 2013 at 0: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. Commented Jun 6, 2013 at 0:50
  • @uncollected: sorry, I should have said - updated question (1.9.1) Commented Jun 6, 2013 at 9:26
  • 1
    @symcbean It might be worth using .done(...) and .fail(...) described here. It looks like an exception object is passed to fail, and that might give more info as to what is going wrong. Commented Jun 6, 2013 at 10:55

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.