Basic AJAX Response (Mootools)

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 :slight_smile:

Thank you in advance !

2009/6/14 Abe C. [email protected]:

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

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

Colin

Colin L. wrote:

2009/6/14 Abe C. [email protected]:

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

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.

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
!? :slight_smile: Thank you for the support !