1

这是一个相当简单的问题,但我找不到解决方案。我将一些 xml 写入到页面上的隐藏 div 中,稍后我会阅读它。问题是在写入 div 时删除了一些引号,因此我无法使用 LoadXML 在 IE 中加载使用 xml

这是 XML

<parameters id='XXX'>
<product_id value='YYY'/>
<report_id value='ZZZ'/>
<list>
    <filter_id value='AAA'/>
</list>
<date_begin value='BBB'/>
<date_end value='CCC'/>
<timeframe_id value='DDD'/>
<chart_id value='EEE'/>

我使用了很多不同的方法,但似乎都不起作用,我正在尝试尽可能多地使用 JQUERY 来防止跨浏览器问题,但任何解决方案都可以。

我将 xml 附加到字符串变量 paramString 中,上面使用

var parametersDiv = "<div id='" + reportDivId + "_params' style='visibility: hidden; display: none'>" + paramString + "</div>";

一切顺利。

但是,当我尝试检索它时,在 IE 中删除了 XXX 周围的引号。因此我无法使用 loadXML() 加载它。我可以破解一个解决方案,但我想正确地做到这一点。

任何解决方案都会有所帮助,我已经浪费了将近一天的时间。

谢谢

京东

4

2 回答 2

1

Try using double quotes and see if that does the job.

If not, another solution to your problem might be to get the XML trough a XMLHttpRequest (Ajax).

jQuery.ajax({
  url: 'yourUrlThatReturnsXML',
  dataType: 'xml',
  success: function (data, textStatus) {
   $(data); // Your XML
  }
});
于 2009-07-30T10:14:04.040 回答
0

How are you inserting these hidden divs into the page? Presumably you are using innerHTML (given that you have a string), but this means that it is being passed through IE's HTML parser. This will turn it into (invalid) HTML, and when you try to retrieve it you will see the effect you describe of attributes being unquoted (and probably other side effects which you happen not to have encountered... yet).

Your best bet is to save a reference to the returned XML document (not a string serialisation thereof) in a variable.

于 2009-07-30T10:58:03.827 回答