# Basic AJAX Response (Mootools)

**URL:** <https://www.ruby-forum.com/t/basic-ajax-response-mootools/170210>\
**Category:** Rails\
**Created:** [June 14, 2009, 2:49am UTC](https://www.ruby-forum.com/t/basic-ajax-response-mootools/170210 "2009-06-14T02:49:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![zamo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/4af34b/32.png) [@zamo](https://www.ruby-forum.com/u/zamo)\
**Post date:** [June 14, 2009, 2:49am UTC](https://www.ruby-forum.com/t/basic-ajax-response-mootools/170210/1 "2009-06-14T02:49:40Z")

</div>

Hi,

I’ve done AJAX calls to Rails’ Controllers before yet never required to  
generate a response back to the view. In this respect, I have tried to  
keep it moronically simple and just add a node to see that it works, yet  
the response doesn’t come through / isn’t interpreted as it should. Long  
story short, code :

// Have to use Mootools to integrate a Moo-specific JS Script

// @.js :

new Request(  
{  
url: ‘bla’  
onSuccess: function(responseText, responseXML)  
{  
console.warn(responseText);  
console.warn(responseXML);  
}  
,  
onFailure: function(xhr)  
{  
alert(STD\_ERR);  
}

}).send();

// @SomeController :

```
  respond_to do |format|
    format.html { head :ok }
    format.xml { render :xml => ({:foo => "bar"}.to_xml) }
  end

```

// Have tried format.json, with all the code involved (:json, .to\_json),  
yet  
// nothing. The to\_xml Method works in irb.

The responseText is “” and responseXML is Null on the callback. This is  
basic stuff, can’t see past my noobness :). So I just want to render  
some xml back to the view, no models or anything yet. I have to mention  
that Content-Length is set on the response header. I’m thinking it’s a  
no-brainer though 🙂

Thank you in advance !

---

<div class="post-metadata">

**Author:** ![zamo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/4af34b/32.png) [@zamo](https://www.ruby-forum.com/u/zamo)\
**Post date:** [June 14, 2009, 10:31am UTC](https://www.ruby-forum.com/t/basic-ajax-response-mootools/170210/2 "2009-06-14T10:31:15Z")

</div>

2009/6/14 Abe C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Â ,  
> Â Â Â Â format.html { head :ok }  
> that Content-Length is set on the response header. I’m thinking it’s a  
> no-brainer though 🙂

Have you proven to yourself that it is getting to your controller  
action ok? For example by breaking in with ruby-debug.

Colin

---

<div class="post-metadata">

**Author:** ![zamo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/4af34b/32.png) [@zamo](https://www.ruby-forum.com/u/zamo)\
**Post date:** [June 14, 2009, 10:35am UTC](https://www.ruby-forum.com/t/basic-ajax-response-mootools/170210/3 "2009-06-14T10:35:27Z")

</div>

Colin L. wrote:

> 2009/6/14 Abe C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):
> 
> > Â ,  
> > Â Â Â Â format.html { head :ok }  
> > that Content-Length is set on the response header. I’m thinking it’s a  
> > no-brainer though 🙂
> 
> Have you proven to yourself that it is getting to your controller  
> action ok? For example by breaking in with ruby-debug.
> 
> Colin

Yes, it is getting there - I’ll look into it now after some sleep :),  
perhaps there’s some nasty oversight. Still getting the same issues as  
before though.

---

<div class="post-metadata">

**Author:** ![zamo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/4af34b/32.png) [@zamo](https://www.ruby-forum.com/u/zamo)\
**Post date:** [June 14, 2009, 11:06am UTC](https://www.ruby-forum.com/t/basic-ajax-response-mootools/170210/4 "2009-06-14T11:06:38Z")

</div>

No-brainer after all, I was sending the request via HEAD, therefore I  
had to set a custom response header, such as :

// @Controller  
respond\_to do |format|  
headers[“My-head”] = “abc”  
format.html { head :ok }  
end

// @JS  
onSuccess: function(responseText, responseXML)  
{  
console.log(responseText);  
console.log(responseXML);  
alert(this.getHeader(‘My-head’));  
},

I changed to GET, used :

// @Controller  
respond\_to do |format|  
format.xml { render :xml =\> ({“abc” =\> “def”}.to\_xml)}  
end

// @JS  
onSuccess: function(responseText, responseXML)  
{  
console.log(responseXML);  
// Getting a XML Document, all fine.  
},

Half an hour though, haha - now I can send and respond to requests, woot  
!? 🙂 Thank you for the support !
