allen
2007-May-09 11:11 UTC
[Problem] Javascript returned by link_to_remote cannot be automatically evaluated.
I created a ajax link using link_to_remote helper. I used the options[:submit] so that I can submit a form using ajax POST method. This ajax call would render a rjs in which I did some DOM operations on the current page. The content of the response is just what I want(some javascript), but it just cannot be evaluated automatically.The link my link_to_remote generates is: <a href="#" id="textSearchLink" onclick="new Ajax.Request(''/searches'', {asynchronous:true, evalScripts:true}); return false;">Search</a> I think the "evalScripts:true" should tell the page to automatically evaluated the returned javascript but the fact is not like that. I''ve used other link_to_remote before, all of which use ajax GET method. I''m thinking whether the returned javascript will not be automatically evaluated if the ajax method is POST. How can I solve this problem? Thanks a lot. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jason Roelofs
2007-May-09 12:53 UTC
Re: [Problem] Javascript returned by link_to_remote cannot be automatically evaluated.
There''s nothing wrong with that link. What is the javascript/RJS you''re sending to the page? Jason On 5/9/07, allen <allenmacyoung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > I created a ajax link using link_to_remote helper. I used the > options[:submit] so that I can submit a form using ajax POST method. > This ajax call would render a rjs in which I did some DOM operations > on the current page. The content of the response is just what I > want(some javascript), but it just cannot be evaluated > automatically.The link my link_to_remote generates is: > > <a href="#" id="textSearchLink" onclick="new Ajax.Request(''/searches'', > {asynchronous:true, evalScripts:true}); return false;">Search</a> > > I think the "evalScripts:true" should tell the page to automatically > evaluated the returned javascript but the fact is not like that. I''ve > used other link_to_remote before, all of which use ajax GET method. > I''m thinking whether the returned javascript will not be automatically > evaluated if the ajax method is POST. > > How can I solve this problem? Thanks a lot. > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
allen
2007-May-10 04:35 UTC
Re: [Problem] Javascript returned by link_to_remote cannot be automatically evaluated.
try { Element.replace("textSearchLink", "<a href=\"#\" onclick=\"new Ajax.Request(''/searches/54'', {asynchronous:true, evalScripts:true, parameters:Form.serialize(''textSearchFieldset'')}); return false;\">Add</a>"); Element.replace("materialPropertySearchLink", "<a href=\"#\" onclick=\"new Ajax.Request(''/searches/54'', {asynchronous:true, evalScripts:true, parameters:Form.serialize(''materialPropertySearchFieldset'')}); return false;\">Add</a>"); Element.replace("metalCompositionSearchLink", "<a href=\"#\" onclick=\"new Ajax.Request(''/searches/54'', {asynchronous:true, evalScripts:true, parameters:Form.serialize(''metalCompositionSearchFieldset'')}); return false;\">Add</a>"); new Insertion.Bottom("searchCriteriaDiv", "<p>\n <a href=\"#\" onclick=\"new Ajax.Request('''', {asynchronous:true, evalScripts:true}); return false;\">Remove</a>\n <label>keyword2</label>\n</p>"); } catch (e) { alert(''RJS error:\n\n'' + e.toString()); alert(''Element.replace(\"textSearchLink\", \"<a href=\\\"#\\\" onclick\\\"new Ajax.Request(\''/searches/54\'', {asynchronous:true, evalScripts:true, parameters:Form.serialize(\''textSearchFieldset\'')}); return false;\\\">Add</a>\"); \nElement.replace(\"materialPropertySearchLink\", \"<a href=\\\"#\\\" onclick=\\\"new Ajax.Request(\''/searches/54\'', {asynchronous:true, evalScripts:true, parameters:Form.serialize(\''materialPropertySearchFieldset\'')}); return false;\\\">Add</a>\"); \nElement.replace(\"metalCompositionSearchLink\", \"<a href=\\\"#\\\" onclick=\\\"new Ajax.Request(\''/searches/54\'', {asynchronous:true, evalScripts:true, parameters:Form.serialize(\''metalCompositionSearchFieldset\'')}); return false;\\\">Add</a>\");\nnew Insertion.Bottom(\"searchCriteriaDiv \", \"<p>\\n <a href=\\\"#\\\" onclick=\\\"new Ajax.Request(\''\'', {asynchronous:true, evalScripts:true}); return false;\\\">Remove</a>\ \n <label>keyword2</label>\\n</p>\");''); throw e } For now, I''m using the option[:complete] to evaluate the above script, so the link should be like: <%= link_to_remote ''Search'', { :url => searches_path, :submit => ''textSearchFieldset'', :complete => ''eval(request.responseText)'' }, { :id => ''textSearchLink'' } %> This does work, but the script should be evaluated automatically other than using :complete => ''eval(...)''. On May 9, 8:53 pm, "Jason Roelofs" <jameskil...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> There''s nothing wrong with that link. What is the javascript/RJS you''re > sending to the page? > > Jason > > On 5/9/07, allen <allenmacyo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > I created a ajax link using link_to_remote helper. I used the > > options[:submit] so that I can submit a form using ajax POST method. > > This ajax call would render a rjs in which I did some DOM operations > > on the current page. The content of the response is just what I > > want(some javascript), but it just cannot be evaluated > > automatically.The link my link_to_remote generates is: > > > <a href="#" id="textSearchLink" onclick="new Ajax.Request(''/searches'', > > {asynchronous:true, evalScripts:true}); return false;">Search</a> > > > I think the "evalScripts:true" should tell the page to automatically > > evaluated the returned javascript but the fact is not like that. I''ve > > used other link_to_remote before, all of which use ajax GET method. > > I''m thinking whether the returned javascript will not be automatically > > evaluated if the ajax method is POST. > > > How can I solve this problem? Thanks a lot.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---