Hi, I am looking for a solution to use ajax.request object. Return response text will be in xml format and I like to know how to parse that xml information, so that I can put those info into the "span" or "div" tags of my html page. Is there any easy way to parse that xml info using prototype library? Thanks, kevin. -- Posted via http://www.ruby-forum.com/.
Hi Kevin, I lifted the following code: onSaveComplete: function(response) { var ajaxResponse = Try.these( function() { return new DOMParser().parseFromString(response.responseText, ''text/xml''); }, function() { var xmldom = new ActiveXObject(''Microsoft.XMLDOM''); xmldom.loadXML(response.responseText); return xmldom; } ); var personid ajaxResponse.getElementsByTagName(''personid'')[0].firstChild.nodeValue; }>From here:http://weblogs.macromedia.com/mesh/archives/2006/01/parsing_xml_in.cfm Hope this helps! Daniel -----Original Message----- From: rails-bounces@lists.rubyonrails.org [mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of kevin knight Sent: Wednesday, February 22, 2006 6:42 PM To: rails@lists.rubyonrails.org Subject: [Rails] prototype ajax + xml response Hi, I am looking for a solution to use ajax.request object. Return response text will be in xml format and I like to know how to parse that xml information, so that I can put those info into the "span" or "div" tags of my html page. Is there any easy way to parse that xml info using prototype library? Thanks, kevin. -- Posted via http://www.ruby-forum.com/. _______________________________________________ Rails mailing list Rails@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails
On Wed, Feb 22, 2006 at 07:13:16PM -1000, Daniel Higginbotham wrote: } Hi Kevin, } } I lifted the following code: } } onSaveComplete: function(response) } { } var ajaxResponse = Try.these( } function() { return new DOMParser().parseFromString(response.responseText, } ''text/xml''); }, } function() { var xmldom = new ActiveXObject(''Microsoft.XMLDOM''); } xmldom.loadXML(response.responseText); return xmldom; } } ); } } var personid } ajaxResponse.getElementsByTagName(''personid'')[0].firstChild.nodeValue; } } } } >From here: } http://weblogs.macromedia.com/mesh/archives/2006/01/parsing_xml_in.cfm Er, what''s wrong with response.responseXML? A parsed XML tree is already available from the XMLHttpRequest object. } Hope this helps! } Daniel --Greg
Daniel Higginbotham wrote:> Hi Kevin, > > I lifted the following code: > > onSaveComplete: function(response) > { > var ajaxResponse = Try.these( > function() { return new > DOMParser().parseFromString(response.responseText, > ''text/xml''); }, > function() { var xmldom = new ActiveXObject(''Microsoft.XMLDOM''); > xmldom.loadXML(response.responseText); return xmldom; } > ); > > var personid > ajaxResponse.getElementsByTagName(''personid'')[0].firstChild.nodeValue; > } > >>From here: > http://weblogs.macromedia.com/mesh/archives/2006/01/parsing_xml_in.cfm > > Hope this helps! > DanielThanks a lot Daniel. I appreciate it. I will try this. Kevin -- Posted via http://www.ruby-forum.com/.
Gregory Seidman wrote:> > Er, what''s wrong with response.responseXML? A parsed XML tree is already > available from the XMLHttpRequest object. > > } Hope this helps! > } Daniel > --GregWhen I tried this (on FireFox IIRC) the responseXML property was null. I read somewhere that this can happen if the mime type isn''t set to "text/xml", and I''ve concluded that prototype doesn''t have a way of setting this. I''d love to be able to rely on .responseXML - do you know how to ensure it will be set? Tony S. -- Posted via http://www.ruby-forum.com/.
On Fri, Feb 24, 2006 at 02:02:51AM +0100, Tony Stevens wrote: } Gregory Seidman wrote: } > } > Er, what''s wrong with response.responseXML? A parsed XML tree is } > already available from the XMLHttpRequest object. } > } > } Hope this helps! } > } Daniel } > --Greg } } When I tried this (on FireFox IIRC) the responseXML property was null. } I read somewhere that this can happen if the mime type isn''t set to } "text/xml", and I''ve concluded that prototype doesn''t have a way of } setting this. } } I''d love to be able to rely on .responseXML - do you know how to ensure } it will be set? Well, the MIME type needs to be set properly. I haven''t touched the prototype library, but my understanding is that it is solely on the JavaScript side, not the Ruby side. In your Rails action you need to set the MIME type. If I am wrong and prototype is on the Rails side as well., modify it. You have the source, after all. Make sure it is setting the MIME type. } Tony S. --Greg
Gregory Seidman wrote:> Well, the MIME type needs to be set properly. I haven''t touched the > prototype library, but my understanding is that it is solely on the > JavaScript side, not the Ruby side. In your Rails action you need to set > the MIME type. > > If I am wrong and prototype is on the Rails side as well., modify it. > You > have the source, after all. Make sure it is setting the MIME type. > > } Tony S. > --GregThankyou! That was just the help I needed. Once I realised the problem was that the rails action wasn''t saying that it was sending XML it gave me a place to start looking. After a while I figured out how to set the response header. It''s all about how you look at it ... Tony S. -- Posted via http://www.ruby-forum.com/.