追加删除引号

发布于 2024-07-29 12:13:00 字数 904 浏览 1 评论 0原文

这是一个相当简单的问题,但我找不到解决方案。 我将一些 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>";

,一切顺利。

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

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

谢谢

京东

This is a fairly simple problem but I can't find a solution.
I write some xml to a hidden div on tha page and i read it later on. The problem is that some quotes are being removed when writing to the div and because of this I can't load the use the xml in IE using LoadXML

this is the 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'/>

I have used alot of different methods but none seem to work, I am trying to use JQUERY as much as possible to prevent cross browser issues, but any solution will do.

I append the xml, in a string variable paramString, above using

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

and it goes in fine.

however when I try to retrieve it the quotes around the XXX are removed in IE. Thus I can't load it using loadXML(). I could hack a solution but i'd like to do it correctly.

Any solutions would be helpful, i've wasted nearly a day on this already.

Thanks

JD

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

混吃等死 2024-08-05 12:14:47

你如何将这些隐藏的 div 插入到页面中? 假设您正在使用innerHTML(假设您有一个字符串),但这意味着它正在通过IE 的HTML 解析器传递。 这会将其转换为(无效)HTML,当您尝试检索它时,您将看到您所描述的属性未加引号的效果(以及可能您碰巧没有遇到过的其他副作用...)。

最好的办法是将返回的 XML 文档(而不是其字符串序列化)的引用保存在变量中。

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.

对你而言 2024-08-05 12:14:21

尝试使用双引号,看看是否有效。

如果没有,问题的另一个解决方案可能是通过 XMLHttpRequest (Ajax) 获取 XML。

jQuery.ajax({
  url: 'yourUrlThatReturnsXML',
  dataType: 'xml',
  success: function (data, textStatus) {
   $(data); // Your XML
  }
});

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
  }
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文