此线程与question非常相似,但我不相信给出的答案(“如果应用程序未部署在同一个共享点站点域上,则无法使用该库”)因为在此页面here作者坚持认为可以通过对象SP.RequestExecutor(appweburl)
。
所以我按照页面中提到的所有步骤操作,最后得到了这段代码:
$(document).ready(function () {
var hostweburl = decodeURIComponent("https://lpl.sharepoint.com/sites/TestPortail");
var appweburl = decodeURIComponent("http://localhost");
var scriptbase = hostweburl + "/_layouts/15/";
// Load the .js file using jQuery's getScript function.
$.getScript( hostweburl + "/_layouts/15/SP.RequestExecutor.js", continueExecution );
function continueExecution() {
var executor;
// Initialize your RequestExecutor object.
executor = new SP.RequestExecutor(appweburl);
console.log(executor); // just to see if created
// You can issue requests here using the executeAsync method
// of the RequestExecutor object.
executor.executeAsync({
url: appweburl + "/_api/SP.AppContextSite(@target)/web/title?@target='" + hostweburl + "'",
method: "GET",
headers: { "Accept": "application/json; odata=verbose" },
success: function (data) {
console.log('Successfully obtained data.');
},
error: function (jqXHR, textStatus, errorThrown) {
console.log('There is an error.');
console.log(jqXHR.status);
console.log(textStatus);
console.log(errorThrown);
}
});
}
});
当我从localhost执行它时,我得到了这个:
我一直在寻找解决方案2天。也许这是因为本地主机不是https,但即使有这个伟大的answer,我还没设法做到(wamp不会启动)。
任何帮助都将不胜感激。