Problem with jQuery getScript

Although it seems like many people seem to be having problems with this in Stack Overflow, I can still see a description of why this is happening incorrectly ( 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 requested script and the expected response (including application mimetype / javascript). But no warnings. There is no mistake. Nothing.

If you subsequently try to refer to something in the script that was supposed to be loaded, it is still undefined (this is a few seconds after the onload event and after the console indicates that the script was found).

Update

I am using jQuery 1.9.1

+6
source share
1 answer

Kudos and thanks uncollected (add an answer and I will mark it as accepted), adding an exception handler, I found a problem ...

An exception occurred that was handled by jQuery silently. Adding a handler via getScript () showed that the problem was "invalid left-side assignment." Unfortunately, this exception does not indicate where the error occurred. Then I tried another way to load the script (create a script element and add it to the body), which meant launching the default handler in the browser, which gave me the line number and bit of the violation code:

 this=null; 

This is intended to clean up an instance of an object to avoid memory leaks and work in Chrome, but not in Firefox.

+1
source

Source: https://habr.com/ru/post/946629/


All Articles