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);
}
});
}