1

While Getting data from SharePoint host header site collection to another host header site collection using rest API we are getting 401 unauthorized error. please help.

Source URL: http://cph.vconnect.com Dispaly Site URL: http://mysite.vconnect.com

$(document).ready(function () {
    getMarqueeListItem();
});

// occurs when a user clicks the read button
function getMarqueeListItem() {
    var listName = "CorpCommunication";
    var url = "http://cph.vconnect.com";
    getListItems(listName, url, function (data) {
        var items = data.d.results;
      alert(items.length);
    }, function (data) {
        marquee_list.empty();
        alert("Ooops, an error occured. Please try again");
    });
}

// READ operation
// listName: The name of the list you want to get items from
// siteurl: The url of the site that the list is in. 
// success: The function to execute if the call is sucesfull
// failure: The function to execute if the call fails
function getListItems(listName, siteurl, success, failure) {
    $.ajax({
        url: siteurl + "/_api/web/lists/getbytitle('" + listName + "')/items",
        method: "GET",
        headers: { "Accept": "application/json; odata=verbose" },
        cache: false,
        success: function (data) {
            success(data);
        },
        error: function (data) {
            failure(data);
        }
        });

}

enter image description here

1 Answer 1

0

It looks like you should enable cors in web.config https://blog.kenaro.com/2014/03/18/cross-site-scripting-with-sharepoint-2013-rest-calls/

Or use another options: ECMAScript or custom wcf-service and access data in code-behind.

2
  • Thanks for your replay, In given article he describe about 2 web application but my issue is different team sites with in same web application Nov 1, 2017 at 6:25
  • In this case you have the same issue: same-origin policy doesn't work https://en.m.wikipedia.org/wiki/Same-origin_policy
    – ted
    Nov 7, 2017 at 11:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.