0

Holla

I am using AJAX to load content into a section of my website. I would like the content that is loaded in to execute some javaScript. However, when i simply include it in the response, it doesn't get evaluated.
Say i request a page, test.htm. That page includes ONLY the following code:

<script language="javaScript">
  function testFunction(){
      alert("HELLO WORLD");
  }
  testFunction();
</script>

Should this function not execute, and alert "Hello world?"

2
Contributors
1
Reply
2
Views
11 Years
Discussion Span
Last Post by Sailor_Jerry
0

Holla

I am using AJAX to load content into a section of my website. I would like the content that is loaded in to execute some javaScript. However, when i simply include it in the response, it doesn't get evaluated.
Say i request a page, test.htm. That page includes ONLY the following code:

<script language="javaScript">
  function testFunction(){
      alert("HELLO WORLD");
  }
  testFunction();
</script>

Should this function not execute, and alert "Hello world?"

No the function will not execute. If you want that to run the script you will need to call a function after your response to "eval" the script for you.

Your new function will need to find and execute the script in the DOM.

pseudo code below

//put your response in a div or something and use the div id to grab the tag with a name = to script
divId.getElementsByTagName("script")
loop...
eval(script.innerHTML)

Running this after you response will run all the scripts on your page.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.