Forum: Ruby on Rails prototype ajax + xml response

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
70a42180747351c8f19990a1449e500e?d=identicon&s=25 Kevin Knight (kevinknight)
on 2006-02-23 05:41
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.
43ec5998360a0cc21b51afef1781e9c0?d=identicon&s=25 Daniel Higginbotham (Guest)
on 2006-02-23 06:15
(Received via mailing list)
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/0...

Hope this helps!
Daniel
675475d0b65710be6d992eb5eb2c61c2?d=identicon&s=25 Gregory Seidman (Guest)
on 2006-02-23 13:48
(Received via mailing list)
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/0...

Er, what's wrong with response.responseXML? A parsed XML tree is already
available from the XMLHttpRequest object.

} Hope this helps!
} Daniel
--Greg
70a42180747351c8f19990a1449e500e?d=identicon&s=25 Kevin Knight (kevinknight)
on 2006-02-23 14:19
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/0...
>
> Hope this helps!
> Daniel


Thanks a lot Daniel. I appreciate it. I will try this.
Kevin
8b9fbb30d0db32b7db07f521749b33f3?d=identicon&s=25 Tony Stevens (Guest)
on 2006-02-24 02:02
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?

Tony S.
675475d0b65710be6d992eb5eb2c61c2?d=identicon&s=25 Gregory Seidman (Guest)
on 2006-02-24 03:31
(Received via mailing list)
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
8b9fbb30d0db32b7db07f521749b33f3?d=identicon&s=25 Tony Stevens (Guest)
on 2006-02-24 07:23
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.
> --Greg

Thankyou! 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.
This topic is locked and can not be replied to.