User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 360,994 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,536 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 3393 | Replies: 1
Reply
Join Date: Jul 2006
Posts: 11
Reputation: AndrewSmith is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
AndrewSmith AndrewSmith is offline Offline
Newbie Poster

Help Ajax - evaluate scripts in response

  #1  
Aug 23rd, 2006
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?"
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2005
Location: Carmel, IN
Posts: 67
Reputation: Sailor_Jerry is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 2
Sailor_Jerry's Avatar
Sailor_Jerry Sailor_Jerry is offline Offline
Junior Poster in Training

Re: Ajax - evaluate scripts in response

  #2  
Aug 24th, 2006
Originally Posted by AndrewSmith View Post
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.
Last edited by Sailor_Jerry : Aug 24th, 2006 at 5:37 pm.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb JavaScript / DHTML / AJAX Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 6:34 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC