Grzesiek Slusarek
2005-Oct-12 04:22 UTC
[Rails-spinoffs] AJAX and disapear javascript tags
Hello everyone. I''m writing web aplications using AJAX (library prototype and scriptaculous). I have situation that I want to change content of one div in my site. I make ajax request to server and getting new content of that div. The problem is that this div should have javascript code (e.g. looks like that <div><script>js code</script> <ul></ul></div>) but haven''t. I can see the server response and everything is ok, (the AJAX data pack is ok, have js code in div), i can see the data just moment before browser is getting it (thanks for greasemonkey!) and still everything is ok, but when browser is changing that div on my site the js code is gone! What I''m doing wrong? or this is not a good way and i shouldn''t doo like that? I cant make it alone so thanks for any help Gregor ---------------------------------------------------- Gdy r?wnowaga mi?dzy ?wiat?em i Ciemno?ci? zostanie zachwiana, na Ziemi rozp?ta si? prawdziwe piek?o: Stra? nocna - film, kt?ry sta? si? legend? - ju? w kinach. http://klik.wp.pl/?adr=www.film.wp.pl%2Ffilm.html%3Fid%3D25159&sid=530
Yeah, I think you''re tackling this the wrong way. You need to split up the response. If you want to show just HTML then show it, if you want to execute javascript then return that separately and then run an eval() on it. Cheers, Bruce -----Original Message----- From: rails-spinoffs-bounces@lists.rubyonrails.org [mailto:rails-spinoffs-bounces@lists.rubyonrails.org]On Behalf Of Grzesiek Slusarek Sent: Wednesday, 12 October 2005 5:21 PM To: rails-spinoffs@lists.rubyonrails.org Subject: [Rails-spinoffs] AJAX and disapear javascript tags <p align=\"left\"><b><font face=\"Arial\" size=\"2\">GFI MailSecurity''s HTML threat engine found HTML scripts in this email and has disabled them.</font></b></p>Hello everyone. I''m writing web aplications using AJAX (library prototype and scriptaculous). I have situation that I want to change content of one div in my site. I make ajax request to server and getting new content of that div. The problem is that this div should have javascript code (e.g. looks like that <div><Xcript><!--js code--></Xcript> <ul></ul></div>) but haven''t. I can see the server response and everything is ok, (the AJAX data pack is ok, have js code in div), i can see the data just moment before browser is getting it (thanks for greasemonkey!) and still everything is ok, but when browser is changing that div on my site the js code is gone! What I''m doing wrong? or this is not a good way and i shouldn''t doo like that? I cant make it alone so thanks for any help Gregor ---------------------------------------------------- -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails-spinoffs/attachments/20051012/4a5d6318/attachment-0001.html
Prototype automatically executes JavaScript code inside <script> tags because your browser won''t when replacing elements contents (some browsers actually *might* execute the code, but it''s not reliable across the supported browsers). It then throws away the script tags, because they are useless. Any functions and code you define inside them will still be available. You need to define the evalScripts:true option in your new Ajax.Updater() call. So you''re not doing anything wrong. :) Thomas Am 12.10.2005 um 09:21 schrieb Grzesiek Slusarek:> Hello everyone. > I''m writing web aplications using AJAX (library prototype and > scriptaculous). I have situation that I want to change content of > one div in my site. I make ajax request to server and getting new > content of that div. The problem is that this div should have > javascript code (e.g. looks like that <div><script>js code</script> > <ul></ul></div>) but haven''t. I can see the server response and > everything is ok, (the AJAX data pack is ok, have js code in div), > i can see the data just moment before browser is getting it (thanks > for greasemonkey!) and still everything is ok, but when browser is > changing that div on my site the js code is gone! What I''m doing > wrong? or this is not a good way and i shouldn''t doo like that? > I cant make it alone so thanks for any help > Gregor > > ---------------------------------------------------- > Gdy r?wnowaga mi?dzy ?wiat?em i Ciemno?ci? zostanie zachwiana, > na Ziemi rozp?ta si? prawdziwe piek?o: > Stra? nocna - film, kt?ry sta? si? legend? - ju? w kinach. > http://klik.wp.pl/?adr=www.film.wp.pl%2Ffilm.html%3Fid%3D25159&sid=530 > > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >