【发布时间】:2015-09-24 11:34:37
【问题描述】:
我实际上正在开发一个 SharePoint 2013 应用程序(SharePoint 托管),并且想要获取 SharePoint 列表的项目标题。因此,我使用了 ajax 的 HTTP-GET-function,但现在在评估返回的 XML-Object 时遇到了问题。
这是我的 ajax 请求代码:
var requestURL = appweburl + "/_api/lists/getbytitle('Fragenkatalog')/items?$select=Title";
$.ajax({
type: "GET",
url: requestURL,
dataType: "xml",
success: function (data) {
showResult(data);
},
error: function (error) {
console.log("ERROR REST");
}
});
在这里得到了我的第一个问题,一开始我尝试从 GET 请求中获取 JSON,因此我将 dataType 更改为 JSON。在我这样做之后,我总是在错误函数中运行。我是否忘记了要添加的内容或为什么它不起作用?
我得到的 XML 文档:
<?xml version="1.0" encoding="UTF-8" ?>
<feed xml:base=http://apps-385225078ec0a6.sp.xyz/_api/ xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml">
<id>fd01da84-e9ec-4872-842d-d3d29af08119</id>
<updated>2015-09-24T09:57:46Z</updated>
<entry m:etag=""1"">
<id>Web/Lists(guid'86b1cc4b-a52e-4d56-a1be-24a2bccd25c5')/Items(1)</id>
<category term="SP.Data.FragenkatalogListItem" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
<link rel="edit" href="Web/Lists(guid'86b1cc4b-a52e-4d56-a1be-24a2bccd25c5')/Items(1)" />
<updated>2015-09-24T09:57:46Z</updated>
<author />
<content type="application/xml">
<m:properties>
<d:Title>Element 1</d:Title>
</m:properties>
</content>
</entry>
<entry m:etag=""1"">
<id>Web/Lists(guid'86b1cc4b-a52e-4d56-a1be-24a2bccd25c5')/Items(2)</id>
<category term="SP.Data.FragenkatalogListItem" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
<link rel="edit" href="Web/Lists(guid'86b1cc4b-a52e-4d56-a1be-24a2bccd25c5')/Items(2)" />
<updated>2015-09-24T09:57:46Z</updated>
<author />
<content type="application/xml">
<m:properties>
<d:Title>Element 2</d:Title>
</m:properties>
</content>
</entry>
</feed>
这是我的结果函数
function showResult(data) {
$(data).find('entry').each(function () {
$(this).find("content").each(function () {
$(this).find("m:properties").each(function () {
var Titel = $(this).find("d:Title").text();
console.log(Titel);
});
});
});
}
现在我想获取列表中每个项目的标题。 但是 .find 在搜索“m:properties”标签时总是失败,这就是为什么我无法获得我正在寻找的信息。
也许你们中的某个人可以帮助我。
感谢和问候
塞巴斯蒂安
【问题讨论】:
标签: javascript json ajax xml sharepoint-2013