javascript 显示用于调试的 object.responseXML 文本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10123887/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Display object.responseXML text for debugging
提问by RyanS
I'm using the following script:
我正在使用以下脚本:
<script type="text/javascript">
function processResult(xData, status) {
$('.feedbackLink').empty();
alert ($(xData.responseXML.xml));
console.log($(xData.responseXML.xml));
$(xData.responseXML).find("z\:row").each(function() {
alert ($(this));
var title = $(this).attr("ows_Title");
var url = $(this).attr("ows_Contact");
$('.feedbackLink').append("<a href="+url+">"+title+"</a>");
});
};
$(document).ready(function() {
alert("ready");
var soapEnv = "<?xml version='1.0' encoding='utf-8'?> <soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'> <soapenv:Body> <GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'> <listName>Pages</listName> <viewFields> <ViewFields> <FieldRef Name='Title' /> <FieldRef Name='Contact' /> </ViewFields> </viewFields> </GetListItems> </soapenv:Body> </soapenv:Envelope>";
$.ajax({
url: "/_vti_bin/lists.asmx",
type: "POST",
dataType: "xml",
data: soapEnv,
complete: processResult,
contentType: "text/xml; charset=\"utf-8\""
});
alert(soapEnv);
});
</script>
But the alert within $(xData.responseXML).find("z\\:row").each(function() {
wont fire. How can I view the responseXML? I want to double check I'm looking for the right identifiers (I dont know where the ows_
came from, I was given this script to work with).
但是里面的警报$(xData.responseXML).find("z\\:row").each(function() {
不会触发。如何查看 responseXML?我想仔细检查我正在寻找正确的标识符(我不知道它ows_
来自哪里,我得到了这个脚本来使用)。
The alert and console.log just displays [object Object].
警报和 console.log 只显示 [object Object]。
Any advice on how to debug this?
关于如何调试这个的任何建议?
采纳答案by Brant Olsen
回答by Maria Ioannidou
Try using console.log(xData.responseText)
to get in the console the actual xml instead of [object Object].
尝试使用console.log(xData.responseText)
在控制台中获取实际的 xml 而不是 [object Object]。
回答by user1566694
in IE:
在 IE 中:
alert(xData.responseXML.xml);
in Firefox (unconfirmed):
在 Firefox 中(未经证实):
var string = (new XMLSerializer()).serializeToString(xData.responseXML); alert(string);
to see the full xml, you can append it to the page (IE):
要查看完整的 xml,您可以将其附加到页面 (IE):
function processResult(xData, status)
{
document.body.innerHTML += htmlEncode(xData.responseXML.xml);
}
function htmlEncode(str)
{
return str.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
}
xData.responseXML.xml is the xml as a string, so converting it to a jquery object isnt needed
xData.responseXML.xml 是字符串形式的 xml,因此不需要将其转换为 jquery 对象