Hello Rob,
Sure I can. There are a lot of sample codes on the internet how to read data in JavaScript from SharePoint. But I think that all sample codes are made only to communicate as JS add-in on SHP. But when I try to use this codes in custom widget I can't get to SHP.
This is the code I try to use:
_onPublishClick:function () {
var hostweburl;
var appweburl;
$(document).ready(function () {
hostweburl = "https://server.domain.cz";
appweburl = "https://server.domain.cz";
$.getScript(hostweburl + "/_layouts/15/SP.RequestExecutor.js", runCrossDomainRequest);
});
function runCrossDomainRequest() {
var executor = new SP.RequestExecutor(appweburl);
executor.executeAsync({
url: appweburl + "/_api/SP.AppContextSite(@target)/web/lists?@target='" + hostweburl + "'",
method: "GET",
headers: { "Accept": "application/json; odata=verbose" },
success: successHandler,
error: errorHandler
});
}
function successHandler(data) {
var jsonObject = JSON.parse(data.body);
console.log(jsonObject.d.Title)
}
function errorHandler(data, errorCode, errorMessage) {
console.log("Could not complete cross-domain call: " + errorMessage)
console.log(data)
}
It jumps to the errorHandler function with this error message: Could not complete cross-domain call: for this URL request of application (https://server.domain.cz) isn't a web of application deployed.
And when I try to print data in errorHandler function all attributes of the ResponseInfo are undefined.
So I think that my widget can't comunicate with SHP but I don't know why.