javascript - How to load an external js file as plain text and assign to variable as a string -
really sorry if dumb question can't seem work. title says trying load external js file , assign variable plain text. project simple js "compiler" stitches number of js files , minifies them one. using $.get() method , appending response string.
the problem js file handles above needs included in final minified file. can load in other files , stitch them fine when load main file sourcing js file seems evaluate , overwrite , stops process.
for time being have got around problem loading in copy .txt file means have keep 2 files date isn't ideal.
i found this article refers javascript loaded via script tags in head.
any appreciated. happily post code not sure bits useful.
update: should have mentioned project needs run entirely client side can't use php/.net pages. files i'm loading in on same domain though.
try use ajax.get() :
var script; $.get('script.js', function(data) { script = data; });
for ajax.get() work inside domain, can't call external domains, if application requires loading external js file guess have use php or server-side language as:
var script; $.get('getscript.php', {url: "http://test.com/script.js"}function(data) { script = data; });
in getscript.php can use curl
or file_get_contents
Comments
Post a Comment