Using a SharePoint 2013 cross-domain library on a simple web page: is this possible?

I have a webpage hosted on a server, say in http://SVR1/path/index.html , and I would like to access some list items on a local SharePoint site hosted on another server, for example, in http://SVR2/sites/mySite/ .

The current installation of SharePoint that I use (not under my control) does not allow to deploy either SharePoint hosting or applications hosted in the application, so I am trying to use the SharePoint cross-domain library to access the necessary list items from a purely external HTML5 / JS / page CSS3 As a user, I have full access rights to the list on my SharePoint site, so I think that there should be no problem reading its elements.

Following the example here , my page looks like this:

 <!doctype html> <html> <head> <!-- Title --> <title>Application Template</title> <script language="javascript" type="text/javascript" src="js/jquery.js"></script> <script language="javascript" type="text/javascript"> var hostweburl = "http://SVR2/sites/mySite"; var appweburl = "http://SVR1/path"; // Load the required SharePoint libraries $(document).ready(function () { $("#renderList").html("Requesting Lists..."); // resources are in URLs in the form: // web_url/_layouts/15/resource var scriptbase = hostweburl + "/_layouts/15"; // Load the js files and continue to the successHandler $.getScript(scriptbase + "/SP.RequestExecutor.js", execCrossDomainRequest); }); /////////////////////////////////////////////////////// // Function to prepare and issue the request to get // SharePoint data function execCrossDomainRequest() { // executor: The RequestExecutor object // Initialize the RequestExecutor with the app web URL. var executor = new SP.RequestExecutor(appweburl); // Issue the call against the host web. // To get the title using REST we can hit the endpoint: // hostweburl/_api/web/lists/getbytitle('listname')/items // The response formats the data in the JSON format. // The functions successHandler and errorHandler attend the // sucess and error events respectively. executor.executeAsync( { url: hostweburl + "/_api/web/lists", method: "GET", headers: { "Accept": "application/json; odata=verbose" }, success: successHandler, error: errorHandler } ); } /////////////////////////////////////////////////////// // Function to handle the success event. // Prints the data to the page. function successHandler(data) { var jsonObject = JSON.parse(data.body); var listsHTML = ""; var results = jsonObject.d.results; for (var i = 0; i < results.length; i++) { listsHTML = listsHTML + "<p><h1>" + results[i].Title + "</h1>" + results[i].Body + "</p><hr>"; } document.getElementById("renderList").innerHTML = listsHTML; } /////////////////////////////////////////////////////// // Function to handle the error event. // Prints the error message to the page. function errorHandler(data, errorCode, errorMessage) { document.getElementById("renderList").innerText = "Could not complete cross-domain call: " + errorMessage; } </script> </head> <body> <h1 id="Root Page" style="text-align:center;">This is the home page</h1> <div id="renderList">Placeholder</div> </body> </html> 

When I load the page in the browser, in the javascript console I get the error message: "Unused error: invalid field or requestInfo.url parameter.".

I get the impression that the problem is with the content of the appweburl variable, which in all the examples I found, is provided by SharePoint as part of the request part in the URL. But this means that the application hosted by the vendor has been deployed to SharePoint - something that I cannot do, and that this application calls the remotely hosted instance.

So the question is: is it possible to use the SharePoint cross-domain library on a page that is completely external to SharePoint, and if so, how do I install hostweburl , appweburl and, possibly, other things to access SharePoint lists?

Thanks in advance.

+6
source share
1 answer

The two URLs you specify, appwebUrl and hostwebUrl are really for use in applications, so I don't think you should use a cross-domain library.

What if you just connect using a method other than the application? For example, you can call a custom web service (from sharepoint) that can connect via CSOM to your SP site, or you can do it directly in javascript.

+1
source

Source: https://habr.com/ru/post/970738/


All Articles