Unable to get info from cross domain into Sharepoint content editor webpart

susmitha 266 Reputation points
2021-06-23T05:46:27.477+00:00

Hello,
We have been trying to display content from different domain using JSON link. We have 2 files (html and JS) which extracts data from JSON and displays over content editor webpart in our Sharepoint 2013. When we use VS code live server it works and content gets displayed.

We have added these 2 files into Site assets library and added link in a content editor which gives error as attached screenshot.
108438-ms-issue-for-ov.png

Can Someone help me with this?

Regards,
Susmitha.

SharePoint Server
SharePoint Server
A family of Microsoft on-premises document management and storage systems.
2,298 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. sadomovalex 3,631 Reputation points
    2021-06-23T14:27:34.28+00:00

    like error description says json file from external site which you try to get is blocked because this external site has The Same Origin Policy. Which means it will allow client-side requests only if they come from the same domain. If you have possibility - you may contact owners of this external site and ask to add your domain to Access-Control-Allow-Origin response header. If not - you may implement server-side proxy (this is possible since you work with SP2013 on-prem) - e.g. custom ashx handler in Layouts folder. This handler will get json file from external site via internal http request and will return it to the caller. In your jQuery code you will then call this ashx handler instead of external site. It will allow to avoid problems with CORS.

    0 comments No comments

  2. MichaelHan-MSFT 18,026 Reputation points
    2021-06-24T07:17:58.747+00:00

    Hi @susmithakatreddy-6036,

    This is security Feature of browsers. We cannot make a Request to another Domain using Javascript.

    As @sadomovalex said, If it's possible, you need to add a "Access-Control-Allow-Origin" Header to the server.


    If an Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.