我从REST web服务的响应的jQuery生成的XML对象:转换引发安全错误
$.ajax({
type: "GET",
url: "http://localhost:9299/foo",
success:function(xml) {
xmlDoc = $.parseXML(xml);
$xml = $(xmlDoc);
// The rest of the code manipulates the structure of the XML
}
});
现在我需要输出的改变XML对象的字符串。我已经发现了这个解决方案,Firefox和其他浏览器:
out = new XMLSerializer().serializeToString($xml);
但我得到这里是以下错误消息:
[Exception... "Security error" code: "1000" nsresult: "0x805303e8 (NS_ERROR_DOM_SECURITY_ERR)" location: "http://localhost/bar"]
所有的文件,我需要的是在本地主机上(包括web服务这为我提供
任何想法,将不胜感激的XML和jQuery库)
编辑:
我已经简化的问题,并尝试下面的代码:
$xml = $('<?xml version="1.0"?><root><element>bla</element><element>blubb</element></root>');
$xml.find("element").each(function() {
alert($(this).text());
});
out = new XMLSerializer().serializeToString($xml);
即使没有任何Web服务调用的问题依旧。 (警报内容正确输出)
编辑2:
感谢凯文B上的评论,我已经得到了有效的解决方案:
$.ajax({
type: "GET",
url: "http://localhost:9299/foo",
dataType: 'xml',
success:function(xml) {
var $xml = $(xml);
// The rest of the code manipulates the structure of the XML
}
});
最后行不更改:
out = new XMLSerializer().serializeToString($xml);
关于您最新的编辑。你没有把它解析为XML。 http://jsfiddle.net/RKpua/7/ – 2012-02-27 17:19:40
你的Edit2,如果你在我的答案中设置'dataType:“xml”',你不需要'$ .parseXML()' – 2012-12-27 16:21:04