I am attempting to create a REST call across domains (we have different farms with different domains in our organization. I am not doing this through an app, but instead I am doing it via a CEWP loading my javascript files on a site page. All I am attempting to do is get the data from a list item. I am attempting this with an AJAX call that has the properties: withCredentials= true
and crossDomain: true
. When I watch the flow in Fiddler, the call is returning a 200 that contains the data in JSON, but before each 200 I get a 401 and I believe this is what my function is getting back. Eventually getting the 200 doesn't do me any good because the 401 is going back to the function call (I think).
Here's my code:
function getListItemByIDAjax(siteURL, listName, itemID, complete, failure) {
$.ajax({
url: siteURL + "/_api/web/lists/getbytitle('" + listName + "')/items(" + itemID + ")",
method: 'GET',
xhrFields: {
withCredentials: true
},
crossDomain:true,
beforeSend: function(XMLHttpRequest){
XMLHttpRequest.setRequestHeader("Accept", "application/json; odata=verbose");
},
cache: true,
success: function (data) {
// Returning the results
complete(data);
},
error: function (data) {
// Returning the results
failure(data);
}
});
}
I can't be the first person trying to accomplish this, but I sure am not finding any information out there that seems to work in this instance. Any help would be greatly appreciated.