doudou_3636 2011-01-27 17:54
浏览 61
已采纳

XML AJAX响应开始时的奇怪字符?

I'm making multiple AJAX calls that returns XML data. When I get the data back, my success function (in JQuery) tries to turn the XML to JSON (using a plugin). I was quickly reminded why I can't assume I would be getting VALID XML back from my AJAX request -- because it turns out a few of the XML responses were invalid -- causing the JSON conversion to fail, script to fail, etc...

My questions are:

  1. What is the best way to check for valid XML on an AJAX response? Or, should I just attempt the JSON conversion, then do a quick check if the JSON object is valid?
  2. In troubleshooting the XML, I found that there are a few strange characters at the VERY beginning of the XML response. Here's an image from my Firebug:

Bad XML Response

Should I try to detect and strip the response of those chars or could there possibly be something wrong with my encoding?

Any help is appreciated! Let me know if more info is needed!

  • 写回答

2条回答 默认 最新

  • duanhong1985 2011-01-27 17:57
    关注

    The strange characters are the Byte Order Mark and are actually valid XML, you can most likely just strip them without risk in most circumstances.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?