使用 jQuery 将 xml 转换为字符串 [英] Convert xml to string with jQuery
本文介绍了使用 jQuery 将 xml 转换为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 jQuery ajax 加载器加载 xml 文件,需要将其转换为字符串,以便我可以使用 PHP 后变量再次将其保存.这样做的最佳方法是什么?
I'm loading an xml file with jQuery ajax loader, and need to convert it to a string so that I can save it out again using PHP post variables. What is the best way to do this?
<script type='text/javascript'>
jQuery.ajax({
type: "GET",
url: "data.xml",
dataType: "xml",
success: parseXML
});
function parseXML(xml) {
var xml_string = jQuery(xml).text(); // (This doesn't work- returns tagless, unformatted text)
alert(xml_string);
}
</script>
推荐答案
这里是:
<script type='text/javascript'>
function xmlToString(xmlData) {
var xmlString;
//IE
if (window.ActiveXObject){
xmlString = xmlData.xml;
}
// code for Mozilla, Firefox, Opera, etc.
else{
xmlString = (new XMLSerializer()).serializeToString(xmlData);
}
return xmlString;
}
</script>
取自此处
这篇关于使用 jQuery 将 xml 转换为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文