I often use a construct like this:
main.html
<div id="placeForJS"></div>
function loadInit () { .. ajax call to stuff things into placeForJS-
div .. }
..
..
inline javascript call to function loadinit ()
This works fine. But sometimes (and I can''t find the pattern), the
stuff returned by the ajax.updater call into the placeforJS div, isn''t
available to the javascript also returned by the call. I use
evalscripts:true, and the javascript itself executes fine. But I can''t
seem to access stuff at times.
For example, in load.php (called by Ajax.Updater ()), I return
<.. javascript code ..
reload = function () { }
validate = function () {
Here I access the tlf0 form, and its fields
.. >
<form name="tlf0" id="tlf0" ...>
<input ..>
<input type="button" onclick="validate();void(0)"
name="ok"
value="OK" />
</form>
So this is stuffed into the placeForJS-DIV. And it works on the first
initial page load, but when I click the OK-button, I get a JS-error
claiming tlf0 has no properties..
Why?
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
This might be a scoping problem. Take a look at this patch: http://dev.rubyonrails.org/ticket/11423 - kangax On Apr 13, 5:00 pm, joho <joh...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I often use a construct like this: > > main.html > <div id="placeForJS"></div> > > function loadInit () { .. ajax call to stuff things into placeForJS- > div .. } > .. > .. > inline javascript call to function loadinit () > > This works fine. But sometimes (and I can''t find the pattern), the > stuff returned by the ajax.updater call into the placeforJS div, isn''t > available to the javascript also returned by the call. I use > evalscripts:true, and the javascript itself executes fine. But I can''t > seem to access stuff at times. > > For example, in load.php (called by Ajax.Updater ()), I return > > <.. javascript code .. > reload = function () { } > > validate = function () { > Here I access the tlf0 form, and its fields > .. > > > <form name="tlf0" id="tlf0" ...> > <input ..> > <input type="button" onclick="validate();void(0)" name="ok" > value="OK" /> > </form> > > So this is stuffed into the placeForJS-DIV. And it works on the first > initial page load, but when I click the OK-button, I get a JS-error > claiming tlf0 has no properties.. > > Why?--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hmm.. indeed. Interesting. Thanks for the response! What''s really odd is that it works in some other places.. and I cannot quite see a difference in the constructs I use. So I naturally wonder what I''m doing different that could "offend" the powers that be and generate this "failure". I''ve only looked at the exec() briefly, but how would I use it .. instead of my Ajax.Updater call, or where I process the response? -joho On Apr 13, 11:36 pm, kangax <kan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> This might be a scoping problem. Take a look at this patch:http://dev.rubyonrails.org/ticket/11423 > > - kangax--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
First, include Prototype.exec from the patch.
Second, replace Ajax.Updater with Ajax.Request:
new Ajax.Request(''example.com'', {
onSuccess: function(r) {
// extract scrtips and evaluate them in a global scope
r.responseText.extractScrtips().map(Prototype.exec);
// update container with remaining content
$(''someContainer'').update(r.responseText.stripScripts());
}
})
Best,
kangax
On Apr 13, 5:50 pm, joho <joh...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> Hmm.. indeed. Interesting.
>
> Thanks for the response!
>
> What''s really odd is that it works in some other places.. and I
cannot
> quite see a difference in the constructs I use.
>
> So I naturally wonder what I''m doing different that could
"offend" the
> powers that be and generate this "failure".
>
> I''ve only looked at the exec() briefly, but how would I use it ..
> instead of my Ajax.Updater call, or where I process the response?
>
> -joho
>
> On Apr 13, 11:36 pm, kangax
<kan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> This might be
a scoping problem. Take a look at this
patch:http://dev.rubyonrails.org/ticket/11423
>
> > - kangax
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
ticket: http://dev.rubyonrails.org/ticket/8112 also has patches modding Prototype to work with Prototype.exec :) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---