dm*****@ameritas.com wrote:
I have a Javascript that is building an XML string and then invokes a
JSP. I need to pass the XML string from the Javascript to the JSP.
What's the best way to do that?
It depends on how you want/can process the XML in the JSP but usually
doing a HTTP POST request with
Content-Type: application/xml
and the XML in the HTTP request body is a good idea:
var httpRequest = null;
if (typeof XMLHttpRequest != 'undefined') {
httpRequest = new XMLHttpRequest();
}
else if (typeof ActiveXObject != 'undefined') {
try {
httpRequest = new ActiveXObject('Microsoft.XMLHTTP');
}
catch (e) {}
}
if (httpRequest != null) {
httpRequest.open('POST', 'whatever.jsp', true);
httpRequest.setRequestHeader('Content-Type', 'application/xml');
httpRequest.onreadystatechange = function () {
if (httpRequest.readyState == 4) {
//deal with response here
}
};
httpRequest.send('<example>Kibology for all</example>');
}
--
Martin Honnen
http://JavaScript.FAQTs.com/