# Link\_to\_remote: return value from action into string?

**URL:** <https://www.ruby-forum.com/t/link-to-remote-return-value-from-action-into-string/155080>\
**Category:** Rails\
**Created:** [December 7, 2008, 4:10pm UTC](https://www.ruby-forum.com/t/link-to-remote-return-value-from-action-into-string/155080 "2008-12-07T16:10:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrpete](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ac91a4/32.png) [@mrpete](https://www.ruby-forum.com/u/mrpete)\
**Post date:** [December 7, 2008, 4:10pm UTC](https://www.ruby-forum.com/t/link-to-remote-return-value-from-action-into-string/155080/1 "2008-12-07T16:10:37Z")

</div>

Is the only way to get a “return value” from the action called through a  
div tag via the :update =\> ‘my\_div’ entry?

I want the value returned to be put into a string that I can manipulate  
in my :complete =\> ‘my\_complete\_function()’

I _did_ try to use the “store value in div” approach then read  
immediately via:

alert(document.getElementById(‘my\_div’).innerHTML.length);

but I get DIFFERENT versions in IE and FireFox !!! BOTH are truncating  
the string (because the string contains marktup) and neither give me the  
verbetim string generated by my action.

Any ideas how to circumvent using div as return value mechanism for  
link\_to\_remote?

Pete

---

<div class="post-metadata">

**Author:** ![mrpete](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ac91a4/32.png) [@mrpete](https://www.ruby-forum.com/u/mrpete)\
**Post date:** [December 7, 2008, 4:20pm UTC](https://www.ruby-forum.com/t/link-to-remote-return-value-from-action-into-string/155080/2 "2008-12-07T16:20:00Z")

</div>

On 7 Dec 2008, at 15:10, Peter A. wrote:

> Is the only way to get a “return value” from the action called  
> through a  
> div tag via the :update =\> ‘my\_div’ entry?
> 
> I want the value returned to be put into a string that I can  
> manipulate  
> in my :complete =\> ‘my\_complete\_function()’

It’s already there. The context in which that javascript runs includes  
an object called request, which the is Ajax request object.  
In particular response.responseText is what you would expect it to be.

Fred

---

<div class="post-metadata">

**Author:** ![mrpete](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ac91a4/32.png) [@mrpete](https://www.ruby-forum.com/u/mrpete)\
**Post date:** [December 10, 2008, 1:26pm UTC](https://www.ruby-forum.com/t/link-to-remote-return-value-from-action-into-string/155080/3 "2008-12-10T13:26:29Z")

</div>

> It’s already there. The context in which that javascript runs includes  
> an object called request, which the is Ajax request object.  
> In particular response.responseText is what you would expect it to be.

Thanks, Fred! However, I just can’t get it to work. If I’m reading  
your comment accurately, it looks like “response” is global?

I’m trying this and it doesn’t work. The first alert fires but the  
second one does not. Plus, there are NO JavaScript errors in FF or  
IE… just “nothing at all”

//link\_to\_remote passes :complete =\> “done()”  
function done() {  
alert(‘done!’);  
alert(response.responseText);  
}

I opened prototype.js to look “under the hood” and I see this:

…  
options.onComplete = (function(response, json) {  
…

Now, I have NO IDEA what this is, but it prompted me to change my code  
to this:

function done(response) {  
alert(‘done!’); //yes  
alert(response.responseText); //no  
}

still, nothing!

Finally, I tried this: I added response as param to my done function  
(see below), and still nothing.

\<%= link\_to\_remote ‘CLICK’,  
:url =\> { :action =\> ‘get\_row’ },  
:update =\> ‘temp’,  
:complete =\> “done(response)” %\>

I’m so confused!
