Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource"

I'm trying to use REST api to query a library to find all the file names in it so that I can populate a dropdown on another site. This apparently violates the CORS policy. How do I get around this since I can't modify the code that SharePoint is using?

I'm using this endpoint: "https:/xxx/sites/xxx/_api/Web/GetFolderByServerRelativeUrl('/sites/yyyy/Database%20documents/" + folderName + "')/files?$select=Name")

  • Is it JSOM or CSOM – nbi Aug 24 '15 at 6:12
  • Have you tried it with an absolute URL reference instead of the relative /sites – Danny '365CSI' Engelman Aug 24 '15 at 10:39
  • I'm using JavaScript and yes this is an absolute URL. – Dinerdo Aug 24 '15 at 13:45

I had your same problem.

SP.RequestExecutor() needs a SharePoint App environment to work.

the ONLY path that solved my problem was to use URL Rewrite on IIS, editing also the jQuery ajax call.

  • Can I ge an idea on how to rewrite url? this is to be done on the source application which is trying to access sharepoint REST URL, right? Any blog which you can point me to – Saksham Jun 12 '19 at 6:53
  • Could you describe the setup of IIS? – Mark L Jul 12 '19 at 3:53
  • you need to first Install the URL Rewrite extension to IIS ( iis.net/downloads/microsoft/url-rewrite ) Then you will be able to "rewrite" the caller to make it appear as it was not a Cross Origin an awesome article about it is here: carlosag.net/articles/… hope it helps – Fabrizio Chionni Jul 15 '19 at 13:59

Thats a security Feature of modern Browsers. You can´t do a Request to another Domain using Javascript. The only Thing you could to is to add a "Access-Control-Allow-Origin" Header to the Webservers (SharePoint) Response. However, if you do not have this possibility, there is no way.


Assuming you are using JSOM

First you need to create object of SP.RequestExecutor() Than you can call cross domain url by using executor.executeAsync()

For more info follow this

For example:

$.getScript(scriptbase + "/_layouts/15/SP.RequestExecutor.js", myFunction);
}); //scriptbase -- > your host web url, which can be fetch from query string

function myFunction(){
 var executor=new SP.RequestExecutor(appWebUrl); //pass app web url

                url: myUrl,
                type: "GET",
                headers: { "Accept": "application/json; odata=verbose" },
                success: function (data) {
                    //success handler
                error: function (xhr) {
                   // error handler
  • SP.RequestExecutor doesn't seem to exist on my SP 2013 site. – Dinerdo Aug 24 '15 at 13:50
  • updated the answer – nbi Aug 24 '15 at 14:33
  • Thank you. That fixed the script loading issue, but it seems to return the error handler each time which doesn't contain any information (blank text for each property). – Dinerdo Aug 24 '15 at 16:02
  • replace the error handler defination with this error: function(data, errorCode, errorMessage) and check for errorMessage value – nbi Aug 24 '15 at 17:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.