我正在使用 JQuery 调用 SharePoint Web 服务 (Webs.asmx) 以获取所有子网站的列表:
$(document).ready(function() {
var hrefParts = window.location.href.split('/');
var wsURL = "";
for (i = 0; i < (hrefParts.length - 2); i++) {
if (i > 0)
wsURL += "/";
wsURL += hrefParts[i];
}
wsURL += "/_vti_bin/Webs.asmx";
var soapEnv =
"<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'> \
<soapenv:Body> \
<GetAllSubWebCollection xmlns='http://schemas.microsoft.com/sharepoint/soap/'> \
</GetAllSubWebCollection > \
</soapenv:Body> \
</soapenv:Envelope>";
$.ajax({
url: wsURL,
beforeSend: function (xhr) {
xhr.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/sharepoint/soap/GetAllSubWebCollection");
},
type: "POST",
dataType: "xml",
data: soapEnv,
complete: processResult,
error:function(xhr,err){
alert("readyState: "+xhr.readyState+"\nstatus: "+xhr.status);
alert("responseText: "+xhr.responseText);
},
contentType: "text/xml; charset=\"utf-8\""
});
});
function processResult(xData, status) {
...
}
但是,由于 beforeSend 调用,我总是遇到登录问题。如果我将其注释掉,我会从 SharePoint 收到“访问被拒绝”错误页面。 我对该网站和所有子网站拥有“完全控制”访问权限。调用不同的Web服务(例如从lists.asmx调用GetListCollection)成功。
这可能是什么问题?
最佳答案
此操作需要网站集管理员访问权限,即使完全控制也是不够的。
您可能需要迭代 GetWebCollection,或者创建一个以提升的权限运行并返回 Web 服务响应的代理页面。
关于jquery - JQuery 和 SharePoint Web 服务的身份验证问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2190182/