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 = <some hash here>
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

···

--
This mail was scanned by BitDefender
For more information please visit http://www.bitdefender.com/links/en/frams.html

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 Victory

···

On 2/6/13 7:34 AM, Ken D'Ambrosio wrote:

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 = <some hash here>
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