在Sharepoint上运行SPServices需要权限吗



我需要Sharepoint的帮助。我尝试了多种方法从列表中检索数据,但几乎没有成功,经过多次阅读和搜索,我仍然没有取得进一步的进展。

我正在使用另一个用户创建的列表,我可以从中添加、编辑和删除项目。当我使用SPServices调用这个列表时,我似乎碰到了一堵墙。这是我第三次尝试访问列表,现在我收到了404响应,而responsetext为空。

URL是正确的,因为它实际上加载了值列表。

如果我有一个空的webURL参数,那么responsetext的参数有一个有用的SOAP响应,说明如下:

<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><soap:Fault><faultcode>soap:Server</faultcode><faultstring>Exception of type 'Microsoft.SharePoint.SoapServer.SoapServerException' was thrown.</faultstring><detail><errorstring xmlns="http://schemas.microsoft.com/sharepoint/soap/">
List does not exist.
The page you selected contains a list that does not exist.  It may have been deleted by another user.
</errorstring><errorcode xmlns="http://schemas.microsoft.com/sharepoint/soap/">0x82000006</errorcode></detail></soap:Fault></soap:Body></soap:Envelope>

这是我的调用,当我定义webURL指向列表时,无论url是什么,它都会返回一个带有responseText=null的http 404。这不是很有帮助。我所指向的Url加载列表。

function getListItems_RFC(){
var url = $().SPServices.SPGetCurrentSite() + 
"/_vti_bin/listdata.svc/RFCExtract";
console.log("getListItems_RFC() "+ url);
$().SPServices({
operation: "GetListItems",
webURL: url,
async: false,
listName: "RFC Extract",
CAMLViewFields: "<ViewFields><FieldRef Name='Title' /></ViewFields>",
completefunc: 
function (xData, Status) {
console.log(Status); //outputs error
console.log(xData); //outputs array responseText:null and status:404
$(xData.responseXML).SPFilterNode("m:properties").each(function() {
var liHtml = "<li>" + $(this).attr("d:Title") + "</li>";
$("#debug").append(liHtml);
});
} 
});
};

我已经通过各种可能的方式修改了url:

var url = $().SPServices.SPGetCurrentSite() + 
"/_vti_bin/listdata.svc/"; //responseText=null, status:404
var url = $().SPServices.SPGetCurrentSite();//responseText=null, status:404
var url = "" //responseText=soapresponse above, status:500

为什么不起作用???我做错了什么???

你能把你的实现改成其他的吗
我认为你的做法很复杂。这里的第三方图书馆是不必要的
好的方法是使用开箱即用的REST API或JSOM。它很容易使用。

我看到你想要得到列表项标题字段
以这种方式使用REST API:
http://siteurl/_api/web/lists/GetByTitle("测试"(/items$select=标题

您可以在这里找到示例:
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/working-with-lists-and-list-items-with-rest
https://www.c-sharpcorner.com/blogs/retrieve-sharepoint-list-items-using-rest-api

可以用于SharePoint 2010:

var myRestApiUrl = _spPageContextInfo.webServerRelativeUrl + "/_vti_bin/ListData.svc/RFCExtract?$select=Title";
var get = function (url) {
return jQuery.ajax({
url: url,
type: "GET",
processData: false,
headers: {
Accept: "application/json;odata=verbose",
}
});
};
get(myRestApiUrl)
.then(function(response){
// TODO: do actions with response
});

最新更新