这是函数调用
'<div class="commentblock">' +getcomment($(this).attr("id"))+'</div>'
功能本身:
function getcomment(identifier) {
var commentmasterstring = "";
$.ajax({
type: "GET",
url: "XML/Thread_" + identifier + ".xml",
dataType: "xml",
success: function (xml) {
{
$(xml).find('comment').each(function () {
commentmasterstring +=
'<div class="commentmain">' +
'<div class="commentuser-info">' + $(this).find('owner').text() +
'</div>' +
'<div class="data">' +
'<p>' +
$(this).find('data').text() +
'</p>' +
'<p>' +
$(this).find('datetime').text() +
'</p>' +
'</div>' +
'</div>'
;
});
}
},
error: function () {
alert("The XML File could not be processed correctly.");
}
});
return commentmasterstring;
}
XML剪辑:
<?xml version="1.0"?>
<!--Individual thread-->
<ThreadDetails>
<comment id="29062015080005199730">
<datetime>June 29 2015, 08:00 AM</datetime>
<owner>Jyotirmoy</owner>
<data>1: one</data> </comment>
<comment id="29062015081941086987">
<datetime>June 29 2015, 08:19 AM</datetime>
<owner>Jyotirmoy</owner>
<data>1: two</data>
</comment>
</ThreadDetails>
执行后,只显示一个空div。我检查过并发现xml路径被正确识别。但是,字符串值赋值导致问题。我无法理解......请帮助..
答案 0 :(得分:0)
如果您还没有.text()
,请尝试将.html()
替换为<{1}}。
使用老式javascript kinda的另一个选项是
$(this).find('datetime').get(0).innerHTML