UNPKG

ondemandspcrossdomainajax

Version:

Enhancement to SPCrossDomainAJAX that simplifies making a one off AJAX call within SharePoint

28 lines (20 loc) 1.67 kB
![DOI Logo](https://www.doi.gov/sites/doi.opengov.ibmcloud.com/themes/custom/doi_gov/logo.png) #SPCrossDomainAJAX OnDemandSPCrossDomainAJAX is a *convenience* further enhances [SPCrossDomainAJAX](https://www.npmjs.com/package/spcrossdomainajax). This package is built for use in SharePoint 2016 and SharePoint Online. Cross Domain AJAX Requests are implemented using the generic interface *ISPCrossDomainAJAX<T, K>* **T** is the data type of the data to be passed in the request body. **K** is the data type of the data to be returned in the promise from *Execute*. *OnDemandSPCrossDomainAJAX<T, K>* #Usage ```TypeScript import {ISPCrossDomainAJAX, SPCrossDomainAJAX, ISPCrossDomainAJAXRequest, ISPCrossDomainAJAXRequestError} from "SPCrossDomainAJAX"; import {OnDemandSPCrossDomainAJAX} from "OnDemandSPCrossDomainAJAX"; // No need to explicitly load SP.Runtime.js, SP.js, and SP.RequestExecutor.js // T parameter is irrelevant for GET which is the default operation const crossDomainHelper:ISPCrossDomainAJAX<void, listInterface> = new OnDemandSPCrossDomainAJAX<void, listInterface>(); crossDomainHelper.Execute({ Method: HTTPMethod.GET; RequestUrl: "/_api/web/lists(guid'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx')/Items" WebUrl: "/"}).then((value:listInterface)=>console.log("success!")).catch((reason: ISPCrossDomainAJAXRequestError) => console.log("Failed with status text: " +reason.statusText)); ``` ************************************************************************************************************************************ [Office of Chief Information Officer](https://www.doi.gov/ocio)