我是否需要权限才能在Sharepoint上运行SPServices?

时间:2018-11-30 01:15:00

标签: sharepoint permissions sharepoint-2010 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。这不是很有帮助。我要指向的网址会加载列表。

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);
                  });
               } 
       });
};

我以各种可能的方式修改了网址:

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

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

1 个答案:

答案 0 :(得分:0)

您可以将实现更改为其他内容吗?
我认为您的方法非常复杂。这里不需要第三方库。
好的方法是使用现成的REST API或JSOM。易于使用。

我看到您想获取列表项“标题”字段。
通过以下方式使用REST API:
http://site url / _api / web / lists / GetByTitle('Test')/ items?$ select = Title

在这里您可以找到示例:
https://docs.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

});
相关问题