Accessing SharePoint List via external html page using .ajax function but getting CORS error

Copper Contributor
 

I need to query SharePoint List from simple javascript, using .ajax call. I need to use a AD user credentials who will have read permissions to the SharePoint Site. I am doing something like this but getting a lots of errors. Any suggestions.

 

var user = "****@AD2012.***";
var passwordtemp = "**********";
$.ajax({
url
: siteURL + "/_api/web/lists/GetByTitle('"+ listName +"')/items" + filterQuery,
method
: "GET",
headers
: { "Accept": "application/json; odata=verbose" },
crossDomain
: true,
beforeSend
: function (xhr) {
xhr
.setRequestHeader('Authorization', make_base_auth(user, passwordtemp)); },
success
: function (data) { // Doing something with data .. }}, error: function (data) { failure(data); } });
} // function ends ..

 

0 Replies