Hello, (I originally posted this on the Prototype-Core group by mistake, sorry) I am running a request via Ajax.Updater with evalScripts = true and an onComplete function. I find that my onComplete function executes before the script content has been evaluated. Looking through prototype.js (v. 1.5.1) this seems to be caused by the scripts being executed as part of this line (1352): setTimeout(function() {html.evalScripts()}, 10); So the onComplete function will always run first. Besides putting a timeout in my onComplete function is there a way to make my script run after the call to evalScripts? Simple example showing this problem: File 1: index.htm <html> <head> <script type="text/javascript" src="prototype.js"></script> <script type="text/javascript"> var x = 10; function tellMe() { alert(x); alert(x); } function populate() { new Ajax.Updater("target", "content.htm", { onComplete: tellMe, evalScripts: true }); } </script> </head> <body> <a href="#" onclick="populate();">Populate</a> <div id="target">Content goes here</div> </body> </html> File 2: content.htm <div>AJAX Content</div> <script type="text/javascript"> x++; </script> Result The first alert shows 10, the second, 11. Thanks, Tim --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Andreas Franke
2007-Nov-19 07:39 UTC
AW: [Rails-spinoffs] Running a script after evalScripts has completed
Hi, do this: new Ajax.Updater("target", "content.htm", { onSuccess:tellMe, evalScripts:true }); Should work. Andreas -----Ursprüngliche Nachricht----- Von: rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org [mailto:rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org] Im Auftrag von Tim Gesendet: Montag, 19. November 2007 08:27 An: Ruby on Rails: Spinoffs Betreff: [Rails-spinoffs] Running a script after evalScripts has completed Hello, (I originally posted this on the Prototype-Core group by mistake, sorry) I am running a request via Ajax.Updater with evalScripts = true and an onComplete function. I find that my onComplete function executes before the script content has been evaluated. Looking through prototype.js (v. 1.5.1) this seems to be caused by the scripts being executed as part of this line (1352): setTimeout(function() {html.evalScripts()}, 10); So the onComplete function will always run first. Besides putting a timeout in my onComplete function is there a way to make my script run after the call to evalScripts? Simple example showing this problem: File 1: index.htm <html> <head> <script type="text/javascript" src="prototype.js"></script> <script type="text/javascript"> var x = 10; function tellMe() { alert(x); alert(x); } function populate() { new Ajax.Updater("target", "content.htm", { onComplete: tellMe, evalScripts: true }); } </script> </head> <body> <a href="#" onclick="populate();">Populate</a> <div id="target">Content goes here</div> </body> </html> File 2: content.htm <div>AJAX Content</div> <script type="text/javascript"> x++; </script> Result The first alert shows 10, the second, 11. Thanks, Tim --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---