Forum: Ruby XML on the server?

Posted by Ken D'Ambrosio (Guest)
on 2013-02-06 14:34
(Received via mailing list)
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
Posted by Ryan Victory (Guest)
on 2013-02-06 15:05
(Received via mailing list)
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
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.