
I traced down a problem described also at http://echo.nextapp.com/site/node/6669 which has the effect, that the textbox "eats" newlines.
It turns out: Echo seems to create XML DOM all correct and everything seems fine. But The content of the inner text node ("<p i=...>text content</p>) gets mangled: Newline characters don't reach the server after passing the XMLHttpRequest object.
Below you'll find a Test page and Servlet to reproduce this problem. I posted a question at http://social.msdn.microsoft.com/Forums/en-US/iewebdevelopment/threads but maybe somebody knows a better place to ask how to tackle this?
Here the HTML/JavaScript code which triggers a request. Please note: This HTML page must be deployed on the same server as the target servlet, as XMLHttpRequest is subject to the same-origin policy:
<!DOCTYPE html>
<html>
<head>
<title>IE9 Bug Demonstration</title>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
</head>
<script language="JavaScript">
MyAjaxClient = {
createDocument: function(namespaceUri, qualifiedName) {
// DOM Level 2 Browsers
var dom;
dom = document.implementation.createDocument(namespaceUri, qualifiedName, null);
dom.charset = "utf-8";
if (!dom.documentElement) {
dom.appendChild(dom.createElement(qualifiedName));
}
return dom;
},
connect: function(messageObject) {
this._xmlHttpRequest = new XMLHttpRequest();
var instance = this;
// Create closure around instance.
this._xmlHttpRequest.onreadystatechange = function() {
if (!instance) {
return;
}
instance._processReadyStateChange();
};
this._xmlHttpRequest.open("POST", "../dump", true);
// Set Content-Type for IE9
this._xmlHttpRequest.setRequestHeader("Content-Type", "text/xml;charset=utf-8");
// Execute request.
this._xmlHttpRequest.send(messageObject);
},
_processReadyStateChange : function() {
}
};
function ie9ajaxrequest() {
var document = MyAjaxClient.createDocument("http://foo.bar/clientmessage", "cmsg");
document.documentElement.setAttribute("t", "init");
document.documentElement.setAttribute("w", "baz");
var cSyncElement = document.createElement("dir");
cSyncElement.setAttribute("proc", "CSync");
var eElement = document.createElement("e");
eElement.setAttribute("t", "foo");
eElement.setAttribute("i", "123");
cSyncElement.appendChild(eElement);
var propertyValue = "abc\n123\ndef\nÖzdemir sült Izdemis\n321";
var pElement = document.createElement("p");
pElement.setAttribute("i", "123");
pElement.setAttribute("n", "text");
pElement.appendChild(document.createTextNode(propertyValue));
cSyncElement.appendChild(pElement);
document.documentElement.appendChild(cSyncElement);
MyAjaxClient.connect(document);
}
</script>
<body>
<h1>Trigger a request</h1>
Press <input type="button" value="Button" onclick="ie9ajaxrequest();"/> to trigger a request.
<p>Özdemir sült Izdemis</p>
</body>
</html>
Here a small Servlet which dumps simply out all input for convenience
public class RequestDumperServlet extends HttpServlet {
private static final Log LOG = LogFactory.getLog("SERVLET");
@SuppressWarnings({"unchecked"})
@Override
public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
LOG.info("");
LOG.info("PARAMETERS:");
Map<String, String[]> set = req.getParameterMap();
for (Map.Entry<String, String[]> param : set.entrySet()) {
LOG.info(param.getKey()+"="+ Arrays.toString(param.getValue()));
}
LOG.info("");
LOG.info("HEADERS:");
Enumeration attributeNames = req.getHeaderNames();
while (attributeNames.hasMoreElements()) {
String name = (String) attributeNames.nextElement();
LOG.info(name+"="+req.getHeader(name));
}
LOG.info("");
LOG.info("CONTENT:");
BufferedReader reader = req.getReader();
String line;
while ((line = reader.readLine()) != null) {
LOG.info(line);
}
LOG.info("---");
}
}
The expected output on all Browser is as follows:
<cmsg xmlns="http://foo.bar/clientmessage" t="init" w="baz"><dir xmlns="" proc="CSync"><e t="foo" i="123"/><p i="123" n="text">abc 123 def Özdemir sült Izdemis 321</p></dir></cmsg>
but in IE9 the server in fact receives the following (Note the leading ? as well as the missing line breaks):
?<cmsg xmlns="http://foo.bar/clientmessage" t="init" w="baz"><dir xmlns="" proc="CSync"><e t="foo" i="123" /><p n="text" abc 123 def Özdemir sült Izdemis 321</p></dir></cmsg>
Anybody hints on this issue or where to ask for in-depth information?
Tod got support here
Take a look at this - maybe you can contact the MS Guy?
http://echo.nextapp.com/site/node/5690
Thanks for the pointer!
Thanks for the pointer! Unfortunately Tod did not post any email so I was unable to extract a contact.
My post on a official IE developer forum on MSDN resulted in the tip to "use <br/> to keep the line breaks" m-)
Finally...
Finally there was some response on the Microsoft forum...
After pointing some Microsoft related guy from a german forum to this topic and doing some tenaciously questions on the english forum there was an answer!
Yeah - some things take time :-)
See here for the two discussions:
http://social.msdn.microsoft.com/Forums/en-US/iewebdevelopment/thread/0e8c403d-3d46-4ba2-899e-54ed2261d1e3
http://answers.microsoft.com/de-de/ie/forum/ie9-windows_7/ie9-verwirft-newlines-bei-xmlhttprequest/8ce3c4ea-d550-408e-aef2-d133635338c7
And the thread here on echo3 forum that also fits to that error:
http://echo.nextapp.com/site/node/6669
--
Ralf