XML on the server?

I’m trying to dip my toes into Ajax, and am attempting to give an XML
reply to the query. And I am completely failing – either it gets
passed, but with an HTML MIME header (which is why I’m guessing it’s not
recognized by the client as XML), OR it barfs and gives a 500-series
server-side error. Here’s what the pertinent code currently looks like
– it’s been through many permutations, but has never quite been right
enough, so I assume I’m doing something dumb:

#!/usr/bin/ruby
require ‘cgi’
comics =
cgi = CGI.new(“html3”) # add HTML generation methods
if(cgi[‘action’]==“foo”)
cgi.out(“application/xml”){
comics.to_xml
}
exit
else

other stuff here

I have a sneaking suspicion I’m completely missing some obvious
point… but darned if I know what. Any pointers?

Thanks much!

-Ken

How are you trying to consume the XML on the client side? If you post
your JavaScript that may help. Also, I’d recommend just looking at using
straight JSON (require ‘json’) and doing comics.to_json instead, it’s
much lighter weight and easier for humans (and JavaScript) to understand
(at least in my opinion).

-Ryan V.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs