I think you have to strip the <script> tags off before you run eval(). I just tried a little test using firebug:
Eval("<script>alert('hello');</script>"); FAIL Eval("alert('hello')"); SUCCEED -- Josh -----Original Message----- From: jquery-en@googlegroups.com [mailto:jquery...@googlegroups.com] On Behalf Of yellow1912 Sent: Friday, January 09, 2009 1:54 PM To: jQuery (English) Subject: [jQuery] Re: How to dynamically load/add inline javascript? I actually did, I put a very simple line alert("testing"); No error, no effect, weird. Regards Raine On Jan 9, 3:35 pm, MorningZ <morni...@gmail.com> wrote: > "I wonder if eval will work correctly in this case? " > > Did you simply just try it? > > On Jan 9, 4:01 pm, yellow1912 <yellow1...@gmail.com> wrote: > > > Thanks Mike, > > > These inline script always come with > > > <script type="text/javascript"><!-- > > // code here > > //--></script> > > > When I use firebug to check the json data returned, it looks like > > this: > > (I just post part of the code here) > > -------------------------------- > > "jscript_inline":"<script language=\"javascript\" type=\"text\/ > > javascript > > > \"><!--\r\nalert('balh');\r\nvar selected;\r\nvar submitter = null;\r > > \nfunction popupWindow(url) {\r > > > \n window.open > > (url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar= no,scrollbars > > > =yes,resizable=yes,copyhistory=no,width=450,height=320,screenX=150,screenY=1 50,top=150,left=150') > > \r\n > > > }\r\nfunction couponpopupWindow(url) {\r\n window.open > > > (url,'couponpopupWindow','toolbar=no,location > > -------------------------------- > > > I wonder if eval will work correctly in this case? > > > Regards > > > Raine > > > On Jan 9, 2:50 pm, "Michael Geary" <m...@mg.to> wrote: > > > > You can execute JavaScript code with the eval function, e.g. > > > > eval( result.jscript ); > > > > -Mike > > > > > From: yellow1912 > > > > > After I submit my form via ajax, I sometimes get back content (json > > > > format) with some inline jscript in one of the fields (i.e: > > > > result.jscript) > > > > > I've been trying to do something like this: > > > > $('#output').append(result.jscript); > > > > > It doesn't seem to work, however. > > > > > (In my case, I can't avoid these inline jscript, so I can't > > > > really put them in external js files to load) > > > > > I really hope someone can shed some light here > > > > > Regards > > > > > Raine