开发者

ajax and $.getScript() to get a new script

开发者 https://www.devze.com 2023-02-13 09:45 出处:网络
I\'m trying to add a js function dynamically so I read about $.getScript(). Correct me if I\'m wrong, but it seems $.getScript() will just call a .js file that\'s already there in the public folder an

I'm trying to add a js function dynamically so I read about $.getScript(). Correct me if I'm wrong, but it seems $.getScript() will just call a .js file that's already there in the public folder and will just sort of "load it" and make it available, but the js file itself being called is just a static js. What I'm trying to do is call a dynamic js script and the content of this js script changes considerably, so it has to come from the server.

  • I think this isn't possible with $.getScript() alone, or is it?
  • If not, I could m开发者_C百科ake an ajax that returns the function syntax, but how do I then add it somehow to the current js or how do I create a js file for it and load that js?
  • I would possibly like to delete the new js later, but that's not a priority.

So can $.getScript() help with this or a combo of $.getScript() and .ajax?


Pekka's comment is correct - jquery doesn't care what the extension of the file is.

$.getScript("dynamicScript.php") will work just fine so long as that file outputs valid script (no script tags needed)

0

精彩评论

暂无评论...
验证码 换一张
取 消