PDA

View Full Version : Dynamic Ajax Content DIVs don't execute scripts



EdBoy
07-15-2007, 11:46 PM
1) Script Title: Dynamic Ajax Content

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex17/ajaxcontent.htm

3) Describe problem: I can't execute <script> tags inside of a div where a page was loaded. Example: test.php has <script>alert('test');</script> in it. When viewed externally, the alert pops up. When loaded into a div, nothing happens.

Is there a way to allow <script> tags to execute inside of a div? I really need this to happen.

EDIT: Apparently, responseText (as in page_request.responseText) doesn't evaluate scripts. Is there a way to override this?

jscheuer1
07-16-2007, 02:24 AM
You are right, of course. However, it really depends upon what you want to do with javascript at the time that the external content is loaded. Obviously, you are not ultimately trying to alert 'test'. If the script is something that normally would run onload of a page, I would direct you here:

http://www.dynamicdrive.com/forums/showthread.php?t=17426

If you need a more involved solution to the onload problem, there is also:

http://www.dynamicdrive.com/forums/showthread.php?t=13003

However, if you just want to load up a script that requires no initialization and have it available, the Dynamic Ajax Content script has the loadobjs() function for just that purpose. Read the demo page for Dynamic Ajax Content thoroughly for information on its usage.

Finally, if all you really want to do is alert 'test' (from the demo page, addition red):


<a href="javascript:alert('test');ajaxpage('test.htm', 'contentarea');">test</a>

EdBoy
07-16-2007, 02:29 AM
Ah, I see.

With a little IRC scouting, someone gave me this nifty trick which fixed all the problems. Thanks for clarifying it, though.

jenz
08-15-2007, 01:26 AM
I'm also having difficulty with external scripts and this ajax code.

I am using external .js files that have no <script> tags. It's for a vertical image scroller within a div. I've tried adding it to the main .js file, pasitng it in to head of the host file with <script> tags, and using the javascript:loadobjs('cool_slider.js') method and my images in the slider will not scroll.

Here's my post.
http://www.dynamicdrive.com/forums/showthread.php?t=23716 :confused: