390 posts
  • Has referred 100+ members
  • Has sold $250,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
+5 more
EugeneO says

I need help from you Javascript / Ajax gurus.

I have a page with a series of links. When a link is clicked a colorbox window opens and the content from the link is displayed in the window via Ajax. This works fine.

The problem I am having is that when I try to load content that includes a script tag, the script tag is not output at all. My understanding is that when content is loaded via Ajax any script tags should be removed from the content and output after the rest of the HTML . For some reason my script tag is not being readded.

I have tested the code in the script tag to make sure it works and it does so I am confident that is not the problem.

Any ideas?

256 posts
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $125,000+ on Envato Market
  • Has been part of the Envato Community for over 5 years
  • Won a competition
+5 more
der says

Well, here’s what you could do: Instead of sending the tags to the client, you could instead send the URLs of such scripts. After you receive the URLs in the AJAX response, you can create an array with those URLs.

You can then pass the array of script urls to head.js. The scripts can be loaded either synchronously or asynchronously (in parallel, but execute in order), your call.

Also, you can run a callback after all the scripts have been loaded, maybe the initialization code that should be run after all the scripts are loaded. If you’re including such initialization code in one of the scripts, there is no need to do so, since the scripts are executed after they are loaded into the DOM .

Hope it helps ;)

by
by
by
by
by
by