getscript

jQuery.getScript() fails to load function

北慕城南 提交于 2019-12-04 05:28:41
问题 I am trying to load a script with a function like: $.getScript('/js/mymy.js').done(function(){ if(readCookie('my_cookie', 'yes')){ /* do sth here */ } }); or $.getScript('/js/mymy.js',function(){ if(readCookie('my_cookie', 'yes')){ /* do sth here */ } }); where "readCookie" is defined in mymy.js but i get an error "readCookie" is not defined... Here 1 & 2 is where i have got help how to do, but it does not work... Any Ideas? i do use jQuery 1.8.0 mymy.js does contain a function: jQuery

“use strict”; + jQuery.getScript() = script can't export to global namespace

断了今生、忘了曾经 提交于 2019-11-30 15:15:35
Suppose I have the following script, called include_strict.js . After it executes I should have window.global1 defined: "use strict"; var globalVar = {}; alert(typeof window.globalVar); But if I include it from a block of javascript with $.getScript("include_strict.js"); The alert says undefined . Why? What is going on here? FYI, that's not what happens if I include the file using a script tag: <script type="text/javascript" src="include_strict.js"></script> Here, I see the expected alert, object . And if I remove "use strict"; , then both jQuery.getScript() and <script>; have the same effect

Can I use jquery getScript() without a callback?

眉间皱痕 提交于 2019-11-30 05:05:41
I need to use a javascript function from an external js file inside another js file. This is basically the code I've tried: $.getScript('js/myHelperFile.js'); myHelperFunction(); This doesn't work - I get an error of "myHelperFunction is not defined". However, this code works: $.getScript('js/myHelperFile.js', function(){myHelperFunction();}); I specifically want to be able to do it the first way - load the file at the top of my file, and then use any functions I need from there on. Is this possible, or am I misunderstanding how getScript works? Doing it "the first way" is not presently *

“use strict”; + jQuery.getScript() = script can't export to global namespace

喜夏-厌秋 提交于 2019-11-29 22:28:18
问题 Suppose I have the following script, called include_strict.js . After it executes I should have window.global1 defined: "use strict"; var globalVar = {}; alert(typeof window.globalVar); But if I include it from a block of javascript with $.getScript("include_strict.js"); The alert says undefined . Why? What is going on here? FYI, that's not what happens if I include the file using a script tag: <script type="text/javascript" src="include_strict.js"></script> Here, I see the expected alert,

Why call $.getScript instead of using the <script> tag directly?

北战南征 提交于 2019-11-29 14:05:00
I don't understand the reason for replacing this: <script src="js/example.js"></script> with this: $.getScript('js/example.js', function() { alert('Load was performed.'); }); Is there a particular reason to use the jQuery version? The only reason I can think of is that you get the callback when the script is loaded. But you can get that callback using a script tag, too, by using the load event (or on really old IE, onreadystatechange ). In contrast, there are several negatives to doing it this way, not least that getScript is subject to the Same Origin Policy , whereas a script tag is not.

Can I use jquery getScript() without a callback?

孤者浪人 提交于 2019-11-29 02:55:27
问题 I need to use a javascript function from an external js file inside another js file. This is basically the code I've tried: $.getScript('js/myHelperFile.js'); myHelperFunction(); This doesn't work - I get an error of "myHelperFunction is not defined". However, this code works: $.getScript('js/myHelperFile.js', function(){myHelperFunction();}); I specifically want to be able to do it the first way - load the file at the top of my file, and then use any functions I need from there on. Is this

jQuery getScript returns an parse error exception

梦想与她 提交于 2019-11-28 11:31:38
I'm trying to load two scripts with the $.getScript function of getting Google Map script, then after that is loaded, I get another script ( goMap ) which makes map applets easily to be made. However, when loaded, the first script of getting Google Map API is good, then the second script returns a parse error and shows this: TypeError: 'undefined' is not a constructor' Yet, I don't know where that is referencing from or which line, I think it must be trying to execute the Geocoder on this file (first line after (function($){ : http://www.pittss.lv/jquery/gomap/js/jquery.gomap-1.3.2.js Here is

Why call $.getScript instead of using the <script> tag directly?

ぃ、小莉子 提交于 2019-11-28 07:41:26
问题 I don't understand the reason for replacing this: <script src="js/example.js"></script> with this: $.getScript('js/example.js', function() { alert('Load was performed.'); }); Is there a particular reason to use the jQuery version? 回答1: The only reason I can think of is that you get the callback when the script is loaded. But you can get that callback using a script tag, too, by using the load event (or on really old IE, onreadystatechange ). In contrast, there are several negatives to doing

How can I include all JavaScript files in a directory via JavaScript file?

为君一笑 提交于 2019-11-27 13:03:07
I have a bunch of JavaScript files that I would like to include in the page, but I don't want to have to keep writing <script type="text/javascript" src="js/file.js"></script> So is there a way to include all files in a directory (unknown size)? Can I do something like... $.getScript("js/*.js"); ... to get all the JavaScript files in the "js" directory? How can I do this using jQuery? In general, this is probably not a great idea, since your html file should only be loading JS files that they actually make use of. Regardless, this would be trivial to do with any server-side scripting language.

Jquery getScript caching

ε祈祈猫儿з 提交于 2019-11-27 12:05:29
By Default $.getScript() disables caching and you can use $.ajaxSetup and set caching to true. When testing if the script is actually cached with Firebug most of the time the script is coming back at 200 (Which means the script is a fresh copy) and one in maybe 20 or 30 times it will come back 304 (meaning it used a cached version). Why is it getting a new copy the vast majority of the time? $.ajaxSetup({ cache: true }); $.getScript( scriptFile ); The files that getScript retrieves have not been edited and the requests are a page change apart. Aristos First lets clarify what is means that the