Accessing the SharePoint list in custom webpart
-
23-12-2020 - |
Domanda
I am creating the webpart in my app for SharePoint 2013 and office 365. I have tried to accessing the SharePoint list in my webpart using ajax request like this,
$.ajax({
type: "GET",
dataType: 'json',
url: siteURL + "/_vti_bin/ListData.svc/" + listName,
error: function (evt) {
alert("Error");
},
success: function (data) {
// Processing the data.
}
});
It throws cross domain accessing error message. If i add a 'Access-Control-Allow-Origin' headers to access the cross domain then it shows "preflight is invalid redirect error" message. How to get the sharepoint list items in custom webpart.
Soluzione
The App runs in a different Domain, so you can't just call another Domain (the HostWeb)
You have to execute through SharePoint's own SP.RequestExecutor
See all SO posts:
https://sharepoint.stackexchange.com/search?q=RequestExecutor
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a sharepoint.stackexchange