My Ajax.Updater is set for evalScripts and it receives this: <script language="JavaScript">complete();</script> It works in FF but not IE. Is the above code the proper way to return scripts? Thanks!
I think you need to have the attribute ''defer'' set to true in order for scripts to run using IE. As in, <script defer="true" language="JavaScript"> // ... </script> -Al On 4/14/06, Daniel Elmore <danielelmore-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> My Ajax.Updater is set for evalScripts and it receives this: > > <script language="JavaScript">complete();</script> > > It works in FF but not IE. Is the above code the proper way to return > scripts? > > Thanks! > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >
Thanks for the info, but that didn''t work. The defer attribute, I think, is mainly for the initial load of a JS heavy page. Isn''t evalScripts a commonly used feature? Could someone who uses it tell me if I am formatting the content properly. Do I need something like this instead: <script language="JavaScript">var temp = complete();</script> Thanks Daniel -----Original Message----- From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Al Sent: Saturday, April 15, 2006 12:46 PM To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: Re: [Rails-spinoffs] evalScripts in IE I think you need to have the attribute ''defer'' set to true in order for scripts to run using IE. As in, <script defer="true" language="JavaScript"> // ... </script> -Al On 4/14/06, Daniel Elmore <danielelmore-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> My Ajax.Updater is set for evalScripts and it receives this: > > <script language="JavaScript">complete();</script> > > It works in FF but not IE. Is the above code the proper way to return > scripts? > > Thanks! > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >_______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
Hey Daniel, You are correct in your assumption. See the following extract from www.sergiopereira.com - Thank you, Mandy. If your server logic returns JavaScript code along with HTML markup, the Ajax.Updater object can evaluate that JavaScript code. To get the object to treat the response as JavaScript, you simply add evalScripts: true; to the list of properties in the last argument of the object constructor. But there''s a caveat. Those script blocks will not be added to the page''s script. As the option name evalScripts suggests, the scripts will be evaluated. What''s the difference, you may ask? Lets assume the requested URL returns something like this: <script language="javascript" type="text/javascript"> function sayHi(){ alert(''Hi''); } </script> <input type=button value="Click Me" onclick="sayHi()"> In case you''ve tried it before, you know it doesn''t work. The reason is that the script block will be evaluated, and evaluating a script like the above will not create a function named sayHi. It will do nothing. To create this function we need to change our script to create the function. See below. <script language="javascript" type="text/javascript"> sayHi = function(){ alert(''Hi''); }; </script> <input type=button value="Click Me" onclick="sayHi()"> Note that in the previous example we did not use the var keyword to declare the variable. Doing so would have created a function object that would be local to the script block (at least in IE). Without the var keyword the function object is scoped to the window, which is our intent. _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
On 4/16/06, Maninder, Singh <mandiv-W2hqgAdRMsX2eFz/2MeuCQ@public.gmane.org> wrote:> See the following extract from www.sergiopereira.com -> In case you''ve tried it before, you know it doesn''t work. The reason is that > the script block will be evaluated, and evaluating a script like the above > will not create a function named sayHi.This is wrong wrong wrong. The function WILL be created but not in the scope some expect it to. Didn''t we discuss the scope of the evaluation just the other day?> sayHi = function(){It would be saver to use window.sayHi, as the above version depends on that there is no sayHi symbol in the scopes up until the global scope. You might overwrite one of the String or Ajax object members. BUT: This is how it works on any browser. If the eval works in one, it works in any. Therefore I do not think this is the problem, as he just calls a global function. Probably, the function just fails, so he should check with the javascript console and use alerts liberally for debugging. Bye, Martin
On 4/16/06, Martin Bialasinski <klingeling-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> BUT: This is how it works on any browser. If the eval works in one, it > works in any. Therefore I do not think this is the problem, as he just > calls a global function. Probably, the function just fails, so he > should check with the javascript console and use alerts liberally for > debugging.Eeek. eval() can behave differently in different browsers based on the input given. Take the following example, which doesn''t work under IE but works fine under Firefox: var myVar = [ value1, value2, value3, // IE doesn''t like the last , ]; Or, maybe I misinterpreted what you meant. Todd
Martin, these are the two methods I''ve tried. Both work in FF but neither in IE. I don''t know how to debug JS in IE. Either way, the JS code is working fine so I don''t know what else to check. <script type="text/javascript">complete();</script> <script type="text/javascript">temp111 = function () { complete(); }; temp111();</script> Thanks for your help -----Original Message----- From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Martin Bialasinski Sent: Sunday, April 16, 2006 3:51 AM To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: Re: [Rails-spinoffs] evalScripts in IE On 4/16/06, Maninder, Singh <mandiv-W2hqgAdRMsX2eFz/2MeuCQ@public.gmane.org> wrote:> See the following extract from www.sergiopereira.com -> In case you''ve tried it before, you know it doesn''t work. The reason isthat> the script block will be evaluated, and evaluating a script like the above > will not create a function named sayHi.This is wrong wrong wrong. The function WILL be created but not in the scope some expect it to. Didn''t we discuss the scope of the evaluation just the other day?> sayHi = function(){It would be saver to use window.sayHi, as the above version depends on that there is no sayHi symbol in the scopes up until the global scope. You might overwrite one of the String or Ajax object members. BUT: This is how it works on any browser. If the eval works in one, it works in any. Therefore I do not think this is the problem, as he just calls a global function. Probably, the function just fails, so he should check with the javascript console and use alerts liberally for debugging. Bye, Martin _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
Debug JS in IE: Internet option->advance->Disable Script Debugging(internet explorer) ALT->U->V->B(break at next statement) On 4/17/06, Daniel Elmore <danielelmore-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Martin, these are the two methods I''ve tried. Both work in FF but neither > in > IE. I don''t know how to debug JS in IE. Either way, the JS code is working > fine so I don''t know what else to check. > > <script type="text/javascript">complete();</script> > > <script type="text/javascript">temp111 = function () { complete(); }; > temp111();</script> > > Thanks for your help > > > -----Original Message----- > From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Martin > Bialasinski > Sent: Sunday, April 16, 2006 3:51 AM > To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > Subject: Re: [Rails-spinoffs] evalScripts in IE > > On 4/16/06, Maninder, Singh <mandiv-W2hqgAdRMsX2eFz/2MeuCQ@public.gmane.org> wrote: > > > See the following extract from www.sergiopereira.com - > > > In case you''ve tried it before, you know it doesn''t work. The reason is > that > > the script block will be evaluated, and evaluating a script like the > above > > will not create a function named sayHi. > > This is wrong wrong wrong. The function WILL be created but not in the > scope some expect it to. Didn''t we discuss the scope of the evaluation > just the other day? > > > sayHi = function(){ > > It would be saver to use window.sayHi, as the above version depends on > that there is no sayHi symbol in the scopes up until the global scope. > You might overwrite one of the String or Ajax object members. > > BUT: This is how it works on any browser. If the eval works in one, it > works in any. Therefore I do not think this is the problem, as he just > calls a global function. Probably, the function just fails, so he > should check with the javascript console and use alerts liberally for > debugging. > > Bye, > Martin > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >-- By RbmxXx _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
The problem there is that your javascript code is invalid in IE. So, the eval cannot finish executing the code.. However, errors thrown during an eval do not get sent to the javascript error dialog (at least, from what I''ve seen). So, you don''t see the error on the page. What Martin was saying is that if you have valid code, the scoping issues are the same in every browser. Greg> -----Original Message----- > From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org[mailto:rails-spinoffs-> bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Todd Ross > Sent: Sunday, April 16, 2006 6:56 AM > To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > Subject: Re: [Rails-spinoffs] evalScripts in IE > > On 4/16/06, Martin Bialasinski <klingeling-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > BUT: This is how it works on any browser. If the eval works in one,it> > works in any. Therefore I do not think this is the problem, as hejust> > calls a global function. Probably, the function just fails, so he > > should check with the javascript console and use alerts liberallyfor> > debugging. > > Eeek. eval() can behave differently in different browsers based on > the input given. Take the following example, which doesn''t work under > IE but works fine under Firefox: > > var myVar = [ > value1, > value2, > value3, // IE doesn''t like the last , > ]; > > Or, maybe I misinterpreted what you meant. > > Todd > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
> The problem there is that your javascript code is invalid in IE.What''s the problem with the code? How should I write it? Can someone who has evalScripts working in IE show me a snippet of the return code. Thanks! -----Original Message----- From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Gregory Hill Sent: Monday, April 17, 2006 9:22 AM To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: RE: [Rails-spinoffs] evalScripts in IE The problem there is that your javascript code is invalid in IE. So, the eval cannot finish executing the code.. However, errors thrown during an eval do not get sent to the javascript error dialog (at least, from what I''ve seen). So, you don''t see the error on the page. What Martin was saying is that if you have valid code, the scoping issues are the same in every browser. Greg> -----Original Message----- > From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org[mailto:rails-spinoffs-> bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Todd Ross > Sent: Sunday, April 16, 2006 6:56 AM > To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > Subject: Re: [Rails-spinoffs] evalScripts in IE > > On 4/16/06, Martin Bialasinski <klingeling-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > BUT: This is how it works on any browser. If the eval works in one,it> > works in any. Therefore I do not think this is the problem, as hejust> > calls a global function. Probably, the function just fails, so he > > should check with the javascript console and use alerts liberallyfor> > debugging. > > Eeek. eval() can behave differently in different browsers based on > the input given. Take the following example, which doesn''t work under > IE but works fine under Firefox: > > var myVar = [ > value1, > value2, > value3, // IE doesn''t like the last , > ]; > > Or, maybe I misinterpreted what you meant. > > Todd > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs_______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
> What''s the problem with the code? How should I write it?I was referring to Todd''s example. He purposely added an extraneous comma at the end of his list that is invalid syntax in IE. I was just explaining what Martin had meant, not about the original issue about evalScripts. I haven''t really ever used evalScripts, so I''m not sure of the proper way to use it. I''m one of those weirdos that returns pure XML and parses it. Or, in some cases, I return pure javascript and just eval the whole thing. I don''t mix javascript and html in the return. I''m sure someone has done it, though, so hopefully they''ll speak up soon. Greg
Just to conclude for anyone watching this thread. The following code format works fine for Evalscripts in FF and IE. <script type="text/javascript">complete();</script> There was a very subtle bug in my code preventing it from running in IE, but there is nothing wrong with the return format or the framework. Daniel Elmore -----Original Message----- From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Gregory Hill Sent: Monday, April 17, 2006 10:26 AM To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: RE: [Rails-spinoffs] evalScripts in IE> What''s the problem with the code? How should I write it?I was referring to Todd''s example. He purposely added an extraneous comma at the end of his list that is invalid syntax in IE. I was just explaining what Martin had meant, not about the original issue about evalScripts. I haven''t really ever used evalScripts, so I''m not sure of the proper way to use it. I''m one of those weirdos that returns pure XML and parses it. Or, in some cases, I return pure javascript and just eval the whole thing. I don''t mix javascript and html in the return. I''m sure someone has done it, though, so hopefully they''ll speak up soon. Greg _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs