我在谷歌上搜索了一个小时,似乎找不到答案。
我在用
$(xml).find('title')
--但它似乎在返回所有节点中的所有“标题”。如何在根节点中获取标题?
<response stat="OK">
<title>Some Document</title>
<menu>
<item>
<title>Some Title</title>
<url>/</url>
</item>
<item>
<title>Some Title 1</title>
<url>/asdfasdf/</url>
</item>
</menu>
</response>
返回“Some DocumentSome TitleSome Title 1”
// Loads the page content and inserts it into the content area
$.ajax({
dataType: 'xml',
url: 'someurl',
success: function(data, textStatus, XMLHttpRequest) {
// returns
console.log($(data).find('title').text());
}
我只想要第一个头衔!我宁愿不使用xpath,我宁愿使用最便宜的解决方案。