# How to get the responseText from an Ajax.request (urgent!)

**URL:** <https://www.ruby-forum.com/t/how-to-get-the-responsetext-from-an-ajax-request-urgent/143587>\
**Category:** Rails\
**Created:** [July 20, 2008, 10:53pm UTC](https://www.ruby-forum.com/t/how-to-get-the-responsetext-from-an-ajax-request-urgent/143587 "2008-07-20T22:53:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![flaubert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/858c86/32.png) [@flaubert](https://www.ruby-forum.com/u/flaubert)\
**Post date:** [July 20, 2008, 10:53pm UTC](https://www.ruby-forum.com/t/how-to-get-the-responsetext-from-an-ajax-request-urgent/143587/1 "2008-07-20T22:53:23Z")

</div>

Hello all

is it possible?  
I have a select list, and “onchange” event i am using a  
remote\_function, when it is completed, I wanted to execute a  
javascript: $(this).next(.‘product\_price’).value =  
“RESPONSE\_TEXT\_FROM\_AJAX\_REQUEST”

there is some way to do this?

---

<div class="post-metadata">

**Author:** ![flaubert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/858c86/32.png) [@flaubert](https://www.ruby-forum.com/u/flaubert)\
**Post date:** [July 20, 2008, 11:17pm UTC](https://www.ruby-forum.com/t/how-to-get-the-responsetext-from-an-ajax-request-urgent/143587/2 "2008-07-20T23:17:22Z")

</div>

On Jul 20, 9:52 pm, flaubert [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hello all
> 
> is it possible?  
> I have a select list, and “onchange” event i am using a  
> remote\_function, when it is completed, I wanted to execute a  
> javascript: $(this).next(.‘product\_price’).value =  
> “RESPONSE\_TEXT\_FROM\_AJAX\_REQUEST”

supply an onComplete or an onSuccess handler, eg  
:complete =\> ‘…’  
what you give will be wrapper in a function declaration where request  
will be the request that completed (and so request.responseText is  
what the server rendered).  
Just check that ‘this’ is what you think it is

Fred

---

<div class="post-metadata">

**Author:** ![flaubert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/858c86/32.png) [@flaubert](https://www.ruby-forum.com/u/flaubert)\
**Post date:** [July 20, 2008, 11:22pm UTC](https://www.ruby-forum.com/t/how-to-get-the-responsetext-from-an-ajax-request-urgent/143587/3 "2008-07-20T23:22:38Z")

</div>

flaubert wrote:

> I have a select list, and “onchange” event i am using a  
> remote\_function, when it is completed, I wanted to execute a  
> javascript: $(this).next(.‘product\_price’).value =  
> “RESPONSE\_TEXT\_FROM\_AJAX\_REQUEST”
> 
> there is some way to do this?

An alternative to the other answer - don’t reply with raw text. Write  
your  
action like this:

def action  
result = whatever(params)  
render :update do |rjs|  
rjs.replace\_html :product\_price, convert\_to\_html(result)  
end  
end

I don’t know how convert\_to\_html will convert your result; its return  
value must  
be a string of well-formed HTML. The benefit is you do all this on the  
server  
side, so the resulting Javascript is more likely to work with more  
browsers.

–  
Phlip
