Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

DIV containing a script

 
Dan Howard
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

What i'm trying to do is have my server side code return the contents of a DIV. This chunk of html code contains a script which is dynamically generated on the server.

The ajax code looks like this in my script:


then...


gridContainer is a table containing the script including all the data that's to be displayed.

First I had a problem because the script would not execute when I assigned the innerHTML property. I found a hack to solve this at: http://24ways.org/advent/have-your-dom-and-script-it-too

This sort-of works. When I initially load the page the script executes but when I assign the innerHTML the *old* script executes. Not the new one with the updated data.

Does any of this make sence?

How do the experts handle dynamic scripts sent back from the XMLHttpRequest?

Thanks
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64971
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
eval();
[ June 26, 2006: Message edited by: Bear Bibeault ]
 
Dan Howard
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bear,

Yes. I can do that but the returned text is a mix of html and a script. Should I try to make it pure javaScript and eval. Maybe I can parse out the script.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
look at prototype.js and it has an evalScript option with its Ajax code

Eric
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64971
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
+1 to using prototype.js.

I rarely write my own Ajax code anymore (unless I'm doing something fairly complex), and the script evaluation feature that Eric mentions will save you the time and effort of isolating the script from the HTML and eval-ing it on your own.
 
Sonny Gill
Ranch Hand
Posts: 1211
IntelliJ IDE Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For another similar approach suggested by Yuriy Fuksenko, see Execute JavaScript function present in HTML fragment loaded using AJAX
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic