0

I have a sharepoint online site were I'm using announcements. These announcements I would like to consume in a Cordova app and also on a HTML5 site that I have on some info screens.

I have been looking into using the REST service and app for sharepoint.

Example:

var requestUri = 'https://site.sharepoint.com/_api/web/lists(guid\'someGuid')/items'; 
var requestHeaders = { 'accept': 'application/json;odata=verbose' }; 
$.ajax(
    { 
        url: requestUri, 
        contentType: 'application/json;odata=verbose', 
        headers: requestHeaders, 
        success: function (response){
            console.log(response);
        }, 
        error: function(error) {
            console.log(error);
    } 
 });

When I run this I get the: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.

I know I can look into trying to enable CORS on sharepoint, or use JSONP.

I was wondering if the path I'm going down here are the correct path or would it be better to create my own WebService and get the data through that?

Any better ways?

thanks

espenk
  • 575
  • 2
  • 8
  • 23
  • I have futher investigated this. There are som posts were people are writing that it may be better to implement a webservice, and then communicate with the sharepoint through that. It just seems like extra work for nothing. Hopefully someone have some good insight about this – espenk Sep 30 '14 at 09:11
  • When I for example tests the code here http://stackoverflow.com/questions/15310195/from-jquery-ajax-to-breeze-js-sharepoint-odata-example?rq=1 I get the same error I'm having – espenk Sep 30 '14 at 09:23

1 Answers1

0

If your Sharepoint online is connected with Azure AD, then you can use Azure AD application access sharepoint REST API with CORS enabled. Follow the steps at https://msdn.microsoft.com/en-us/office/office365/howto/create-web-apps-using-CORS-to-access-files-in-Office-365

praju
  • 56
  • 3