在xml json响应中获取html标记 - jquery ajax

时间:2014-08-25 12:54:52

标签: c# javascript jquery html ajax

我有一个名为 InnerHtml 的xml标记,其中包含html字段的标记。

C#

Result = "<?xml version='1.0' encoding='UTF-8'?><GETRESPONSE><FIELDS><FIELD><LABEL>FIRST NAME</LABEL><INNERHTML><div class='form-group'><label>First Name</label><input  id='txtFirstName' type='text' pattern='[0-9]{9,9}' class='large' /><label id='Error-FirstName' class='error'></label></div></INNERHTML></FIELD></FIELDS></GETRESPONSE>";
XmlDocument doc = new XmlDocument();
doc.LoadXml(Result);
Result = JsonConvert.SerializeXmlNode(doc);

我正在进行jquery ajax调用并返回上面的响应。现在我想从上面的XML / JSON响应中提取InnerHtml并附加到我现有的html标记

Jquery Ajax Call

success: function (data) {
var i;
var html;
var fieldLength = data.GETBILLERDETAILSRESPONSE.FIELDS.FIELD.length;
for (i = 0; i < fieldLength; i++) {
    console.log(JSON.stringify(data.GETRESPONSE.FIELDS.FIELD[i].INNERHTML));
}
}

我在控制台中获得的是

{"div":{"@class":"form-group","label":["First Bane",{"@id":"Error-FirstName","@class":"error"}],"input":{"@id":"txtFirstName","@type":"text","@pattern":"[0-9]{9,9}","@class":"large"}}}

但我想要Clear Markup而不是

1 个答案:

答案 0 :(得分:2)

尝试将html放在CDATA这样的

Result = "<?xml version='1.0' encoding='UTF-8'?><GETRESPONSE><FIELDS><FIELD><LABEL>FIRST NAME</LABEL><INNERHTML><![CDATA[<div class='form-group'><label>First Name</label><input  id='txtFirstName' type='text' pattern='[0-9]{9,9}' class='large' /><label id='Error-FirstName' class='error'></label></div>]]></INNERHTML></FIELD></FIELDS></GETRESPONSE>";