开发者

Ajax response including special characters

I am trying to get a response xml which has special characters in it. This is failing in IE but in Mozilla it is working fine. Pls let me know how to fix this.

Here's the code:

request.setCharacterEncoding("UTF-8");
response.setContentType("text/xml; charset=UTF-8");
response.setHeader("Cache-Control", "no-cache");
response.getWriter().write("<xml><valid><![CDATA[2189971_Bright Starts bath time foam ©®!@&a开发者_运维百科mp; toys each]]></valid><productid>123</productid></xml>");


Try adding the encoding in the XML itself:

response.getWriter().write("<?xml version=\"1.0\" encoding=\"UTF-8\"?><root><valid><![CDATA[2189971_Bright Starts bath time foam ©®!@& toys each]]></valid><productid>123</productid></root>");


Most likely your XML is invalid - you are specifying UTF8 encoding in the XML but writing code probably does not output UTF8. Check out what browser receives with some HTTP watcher (likle Fiddler) to make sure response is properly UTF8 encoded (the characters you are having problem with must be encode as their are above ASCII range).

Not sure what language/framework you are using, but setting encoding on request and writing to response looks suspicious.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜