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

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.

  • 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 – Pradeep Kolli Nov 1 '17 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 '17 at 11:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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