Question

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.

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top