Forum Discussion
Waqar Muneer
Dec 25, 2016Copper Contributor
How to get list from different site using Sharepiont framework like cross-domain library
I want to get the following cross-domain library functionality in Sharepoint framework:
var executor = new SP.RequestExecutor(appweburl); executor.executeAsync( { url: appweburl + "/_api/SP.AppContextSite(@target)/web/lists?@target='" + hostweburl + "'", method: "GET", success: successHandler, error: errorHandler } );
https://msdn.microsoft.com/en-us/library/office/jj164022.aspx
Please suggest!
Hi Waqar,
It is possible to use JSOM or SP.RequestExecutor in SPFx's web parts too, when corresponding .js files are loaded explicitly, e.g.:
var hostweburl = _spPageContextInfo.webAbsoluteUrl; var scriptbase = hostweburl + '/_layouts/15/'; $.getScript(scriptbase + 'SP.Runtime.js', function () { $.getScript(scriptbase + 'SP.js', function () { $.getScript(scriptbase + 'SP.RequestExecutor.js', execCrossDomainRequest); }); }); function execCrossDomainRequest () { var appweburl = '[..web absolute url..]'; var executor = new SP.RequestExecutor(appweburl); executor.executeAsync({ url: appweburl + '/_api/web/lists', method: 'GET', headers: { "Accept": "application/json; odata=verbose" }, success: function(results) { console.log(results.body); }, error: function(sender, args) { console.log('Error: ' + args.get_message() + ' ' + args.get_stackTrace()); } }); }
P.S.
I can't check it for sure at the moment, yet this should work.