0

I have a page where is some of JSON data stored like this

{
    "video": {
        "user": {
            "first_name": "Curtis",
            "last_name": "Shoch"
        },
        "name": "Darwin Digital",
        "location": "Kennesaw",
        "video_type": "c",
        "created": "2018-01-16T13:11:11.326636Z"
    }
}

I need to take this data and display it on another page, o I tried to do something like this

var getJSON = function(url, callback) {
    var xhr = new XMLHttpRequest();
    xhr.open('get', url, true);
    xhr.responseType = 'json';
    xhr.onload = function() {
      var status = xhr.status;
      if (status == 200) {
        callback(null, xhr.response);
      } else {
        callback(status);
      }
    };
    xhr.send();
};
getJSON('https://dev.truthify.com/api/deeplink/info/bf76b0bd-5210-4c55-af23-c9689ffec536/', function(err, data) {
  if (err != null) {
    alert('Something went wrong: ' + err);
  } else {
    result.innerText = video.name;
  }

But I got a message

No Access-Control-Allow-Origin

Header is present on the requested resource because I am using source from another website and it is blocked. So is there any why to bypass this, or some other way to take this data.

AA Shakil
  • 538
  • 4
  • 14
Marko Petković
  • 185
  • 1
  • 16

1 Answers1

0

You are getting and json and try to send it in another url in a different origin domain. In order to access a server on different origin domain u have to make a cors request (Cross-Origin Resource Sharing) . This means you have to set an "Access-Control-Allow-Origin" header in order for your client agent to gain permission on the server.

Dionisis K
  • 614
  • 5
  • 17