# How to send back a response to an Ajax.request call

**URL:** <https://www.ruby-forum.com/t/how-to-send-back-a-response-to-an-ajax-request-call/185546>\
**Category:** Rails\
**Created:** [March 22, 2010, 4:05pm UTC](https://www.ruby-forum.com/t/how-to-send-back-a-response-to-an-ajax-request-call/185546 "2010-03-22T16:05:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mcieong](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/c37758/32.png) [@mcieong](https://www.ruby-forum.com/u/mcieong)\
**Post date:** [March 22, 2010, 4:05pm UTC](https://www.ruby-forum.com/t/how-to-send-back-a-response-to-an-ajax-request-call/185546/1 "2010-03-22T16:05:53Z")

</div>

Hello, I have the following Ajax call which invoke the action  
“check\_skills”

```
new Ajax.Request('/persons/check_skills'
    { method:'post',
  asynchronous: false,
  evalScripts:false,
  onSuccess: function(transport){
    var response = transport.responseText || "no response text";
    alert("Success! \n\n" + response); },
    onFailure: function(){
      alert('Something went wrong...')
      }
    });

```

The action did get called but the above code always go to “onFailure”  
part, doesn’t anyone konw how the action “check\_skills” can return some  
value back to the Ajax.request call?

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![mcieong](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/c37758/32.png) [@mcieong](https://www.ruby-forum.com/u/mcieong)\
**Post date:** [March 22, 2010, 4:31pm UTC](https://www.ruby-forum.com/t/how-to-send-back-a-response-to-an-ajax-request-call/185546/2 "2010-03-22T16:31:02Z")

</div>

On Mar 22, 3:05 pm, Mc Ieong [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> onFailure: function(){
> alert('Something went wrong...')
> }
> });
> 
> ```
> 
> The action did get called but the above code always go to “onFailure”  
> part, doesn’t anyone konw how the action “check\_skills” can return some  
> value back to the Ajax.request call?

What response is it returning ?

Fred

---

<div class="post-metadata">

**Author:** ![mcieong](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/c37758/32.png) [@mcieong](https://www.ruby-forum.com/u/mcieong)\
**Post date:** [March 23, 2010, 12:21am UTC](https://www.ruby-forum.com/t/how-to-send-back-a-response-to-an-ajax-request-call/185546/3 "2010-03-23T00:21:25Z")

</div>

Frederick C. wrote:

> On Mar 22, 3:05ï¿½pm, Mc Ieong [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > ï¿½ ï¿½ ï¿½ ï¿½ onFailure: function(){  
> > ï¿½ ï¿½ ï¿½ ï¿½ ï¿½ alert(‘Something went wrong…’)  
> > ï¿½ ï¿½ ï¿½ ï¿½ ï¿½ }  
> > ï¿½ ï¿½ ï¿½ ï¿½ });
> > 
> > The action did get called but the above code always go to “onFailure”  
> > part, doesn’t anyone konw how the action “check\_skills” can return some  
> > value back to the Ajax.request call?
> 
> What response is it returning ?
> 
> Fred

Sorry, I got it wrong: I didn’t render anything in the action, now is  
okay when I add this statement in the action:

```
render :js => "alert('Render succeed.')"

```

Thank you very much!

Ieong
