# \[Problem\] Javascript returned by link\_to\_remote cannot be au

**URL:** <https://www.ruby-forum.com/t/problem-javascript-returned-by-link-to-remote-cannot-be-au/103698>\
**Category:** Rails\
**Created:** [May 9, 2007, 1:12pm UTC](https://www.ruby-forum.com/t/problem-javascript-returned-by-link-to-remote-cannot-be-au/103698 "2007-05-09T13:12:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![allen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/bbce88/32.png) [@allen](https://www.ruby-forum.com/u/allen)\
**Post date:** [May 9, 2007, 1:12pm UTC](https://www.ruby-forum.com/t/problem-javascript-returned-by-link-to-remote-cannot-be-au/103698/1 "2007-05-09T13:12:17Z")

</div>

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:

Search

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.

---

<div class="post-metadata">

**Author:** ![allen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/bbce88/32.png) [@allen](https://www.ruby-forum.com/u/allen)\
**Post date:** [May 9, 2007, 2:54pm UTC](https://www.ruby-forum.com/t/problem-javascript-returned-by-link-to-remote-cannot-be-au/103698/2 "2007-05-09T14:54:31Z")

</div>

There’s nothing wrong with that link. What is the javascript/RJS you’re  
sending to the page?

Jason

---

<div class="post-metadata">

**Author:** ![allen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/bbce88/32.png) [@allen](https://www.ruby-forum.com/u/allen)\
**Post date:** [May 10, 2007, 6:36am UTC](https://www.ruby-forum.com/t/problem-javascript-returned-by-link-to-remote-cannot-be-au/103698/3 "2007-05-10T06:36:24Z")

</div>

try {

```
Element.replace("textSearchLink", "<a href=\"#\" onclick=\"new

```

Ajax.Request(’/searches/54’, {asynchronous:true, evalScripts:true,  
parameters:Form.serialize(‘textSearchFieldset’)});  
return false;"\>Add");  
Element.replace(“materialPropertySearchLink”, “\<a href=”#"  
onclick=“new Ajax.Request(’/searches/54’, {asynchronous:true,  
evalScripts:true,  
parameters:Form.serialize(‘materialPropertySearchFieldset’)});  
return false;”\>Add");  
Element.replace(“metalCompositionSearchLink”, “\<a href=”#"  
onclick=“new Ajax.Request(’/searches/54’, {asynchronous:true,  
evalScripts:true,  
parameters:Form.serialize(‘metalCompositionSearchFieldset’)});  
return false;”\>Add");  
new Insertion.Bottom(“searchCriteriaDiv”, “

\n \<a href=”#"  
onclick=“new Ajax.Request(’’, {asynchronous:true, evalScripts:true});  
return false;”\>Remove\n  
keyword2\n

");

} 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");  
\nElement.replace(“materialPropertySearchLink”, “\<a href=\”#\"  
onclick=\“new Ajax.Request(’/searches/54’, {asynchronous:true,  
evalScripts:true,  
parameters:Form.serialize(‘materialPropertySearchFieldset’)});  
return false;\”\>Add");  
\nElement.replace(“metalCompositionSearchLink”, “\<a href=\”#\"  
onclick=\“new Ajax.Request(’/searches/54’, {asynchronous:true,  
evalScripts:true,  
parameters:Form.serialize(‘metalCompositionSearchFieldset’)});  
return false;\”\>Add");\nnew Insertion.Bottom(“searchCriteriaDiv  
“, “

\n \<a href=\”#\” onclick=\“new Ajax.Request(’’,  
{asynchronous:true, evalScripts:true}); return false;\”\>Remove  
\n keyword2\n

”);’); 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(…)’.
