Hi all,
I was hoping somebody could help me work this one out or recommend an alternative.
I have a SharePoint online site with a list of data. I also have built a Cordova app, with a HTML page, and in JavaScript i am trying to connect to the SharePoint online lists via REST, using a simple call that i know works from within a SP online page.
function getAssets(){ var ListName = "Assets"; var ListUrl = "_api/Web/Lists/GetByTitle('" + ListName + "')/Items"; var FilterUrl = "?$select=Title"; $.ajax({ async: false, url: SiteURL + ListUrl + FilterUrl, type: "GET", headers: {"accept": "application/json;odata=verbose", }, success: function (assetData) { var assetCount = assetData.d.results.length; for (i = 0; i < assetCount; i++) { var assetName = assetData.d.results[i].Title; // Add each asset to an array ssetArray.push(assetName); }; }, error: function(error){alert(JSON.stringify(error));} }); };
Unfortunately i get an error in the console:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://mySPONLINEsite.sharepoint.com/sites/Assets_api/Web/Lists/GetByTitle('Assets')/Items?$select=Title. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).
I assume this is because my Cordova is http and SP online is https? i usually do all of my development within SharePoint so i haven't faced a cross origin issue before. from some googling I've found ways to fix this for an onpremise SharePoint by editing config in IIS but obviously i cant do this with SharePoint online.
Any help or advice on alternative ways to connect to SharePoint lists, or even alternative cloud tables i could use to store the data is very much appreciated!