在我的ASP.NET MVC 5网站中,我有以下场景:
当用户单击某个按钮时,它会调用一个返回表示XML的字符串的JsonResult。 但是当我尝试在div上解散它时,我只得到这个字符串的节点值。
<div id="xmlContent"/> <script language="javascript"> function CustomButtonClick(s, e) { var gridKey = s.GetRowKey(e.visibleIndex); if (e.buttonID === 'btnShowXmlContent') { $.getJSON('@Url.Action("GetXmlContent")', { gridKey: gridKey }, function (data) { alert(data); $('#xmlContent').html(data); pcXmlContent.Show(); }); }; } </script>纯XML:
<?xml version="1.0" encoding="utf-16"?> <HEADER> <NumeroOperacao>201406030927460355</NumeroOperacao> </HEADER> <MESSAGE> <ERROR>Object reference not set to an instance of an object.</ERROR> </MESSAGE>这个xml的HTML版本:
201406030927460355 Object reference not set to an instance of an object.我想知道如何将这个xml显示为普通的xml? 谢谢
In my ASP.NET MVC 5 website i have the following scenario:
When user clicks on a button, it calls an JsonResult that returns a string representing a XML. but when i try to displey it on a div, i get just the node values of this string.
<div id="xmlContent"/> <script language="javascript"> function CustomButtonClick(s, e) { var gridKey = s.GetRowKey(e.visibleIndex); if (e.buttonID === 'btnShowXmlContent') { $.getJSON('@Url.Action("GetXmlContent")', { gridKey: gridKey }, function (data) { alert(data); $('#xmlContent').html(data); pcXmlContent.Show(); }); }; } </script>The plain XML:
<?xml version="1.0" encoding="utf-16"?> <HEADER> <NumeroOperacao>201406030927460355</NumeroOperacao> </HEADER> <MESSAGE> <ERROR>Object reference not set to an instance of an object.</ERROR> </MESSAGE>The HTML version of this xml:
201406030927460355 Object reference not set to an instance of an object.I would like to know how can i display this xml as plain xml? Thanks
最满意答案
jQuery的html()函数接受HTML,因为XML 看起来像HTML(并且浏览器不介意)它将创建HEADER和NumeroOperacao等作为HTML节点,这样只留下文本节点可见。
使用text()将值添加为文本。
jQuery's html() function accepts HTML, since XML looks like HTML (and the browser doesn't mind) it will create HEADER and NumeroOperacao etc. as HTML nodes, which leaves just the textnodes visible.
Use text() to add the value as text.
如何在html中显示表示XML的字符串?(How to display a string representing an XML in html?)在我的ASP.NET MVC 5网站中,我有以下场景:
当用户单击某个按钮时,它会调用一个返回表示XML的字符串的JsonResult。 但是当我尝试在div上解散它时,我只得到这个字符串的节点值。
<div id="xmlContent"/> <script language="javascript"> function CustomButtonClick(s, e) { var gridKey = s.GetRowKey(e.visibleIndex); if (e.buttonID === 'btnShowXmlContent') { $.getJSON('@Url.Action("GetXmlContent")', { gridKey: gridKey }, function (data) { alert(data); $('#xmlContent').html(data); pcXmlContent.Show(); }); }; } </script>纯XML:
<?xml version="1.0" encoding="utf-16"?> <HEADER> <NumeroOperacao>201406030927460355</NumeroOperacao> </HEADER> <MESSAGE> <ERROR>Object reference not set to an instance of an object.</ERROR> </MESSAGE>这个xml的HTML版本:
201406030927460355 Object reference not set to an instance of an object.我想知道如何将这个xml显示为普通的xml? 谢谢
In my ASP.NET MVC 5 website i have the following scenario:
When user clicks on a button, it calls an JsonResult that returns a string representing a XML. but when i try to displey it on a div, i get just the node values of this string.
<div id="xmlContent"/> <script language="javascript"> function CustomButtonClick(s, e) { var gridKey = s.GetRowKey(e.visibleIndex); if (e.buttonID === 'btnShowXmlContent') { $.getJSON('@Url.Action("GetXmlContent")', { gridKey: gridKey }, function (data) { alert(data); $('#xmlContent').html(data); pcXmlContent.Show(); }); }; } </script>The plain XML:
<?xml version="1.0" encoding="utf-16"?> <HEADER> <NumeroOperacao>201406030927460355</NumeroOperacao> </HEADER> <MESSAGE> <ERROR>Object reference not set to an instance of an object.</ERROR> </MESSAGE>The HTML version of this xml:
201406030927460355 Object reference not set to an instance of an object.I would like to know how can i display this xml as plain xml? Thanks
最满意答案
jQuery的html()函数接受HTML,因为XML 看起来像HTML(并且浏览器不介意)它将创建HEADER和NumeroOperacao等作为HTML节点,这样只留下文本节点可见。
使用text()将值添加为文本。
jQuery's html() function accepts HTML, since XML looks like HTML (and the browser doesn't mind) it will create HEADER and NumeroOperacao etc. as HTML nodes, which leaves just the textnodes visible.
Use text() to add the value as text.
发布评论