SharePoint add-in [SharePoint hosted app in Office 365] Rest api call Cross Origin Resource Sharing error?

311 views Asked by At

When i tired to get list title from developer site present in SharePoint online, i get CROS error. I have provided full permission to list and web in AppManifest.xml;

It is a simple ajax call that consume Sharepoint api rest services

Code:-

function ajaxcall() {
    var url1 = "https://xxxlll365.sharepoint.com/sites/devsite/_api/web/lists/getbytitle('xxx')/items?$select=Title";

    $.ajax({

        url: url1,
        dataType: 'json', //tired xml,jsonp, crossdoman:true [no big change]
        cros: true,
        success: function (result) {
            $("#div1").html(result);
        }
    });

Console Error XMLHttpRequest for https://xxxlll365.sharepoint.com/sites/devsite/_api/web/lists/getbytitle('xxx')/items?$select=Title required Cross Origin Resource Sharing (CORS)."Error"

Tired with angularJS and got same error as above !

2

There are 2 answers

0
Siddharth Jain On
0
Estefano Costa On

Try include in the header these options:

"Control-Allow-Origin","https://xxxlll365.sharepoint.com")

"Origin","https://xxxlll365.sharepoint.com")