0

I'm working with Vue 2.2 and trying to get some data from a http.get request into my data.

I've done the following:

Vue.component('projects', {
    template: '',
    data: function() {
        return {
            projects: [],
        }
    },
    created: function() {
        // GET request
        this.$http.get('http://url/data.json', { headers: { 'Access-Control-Allow-Origin': '*' }}).then(function (data) {
            // set data on vm
            this.$set('projects', data)
            console.log(data);

        }
    }

});

var project = new Vue({
    el: '#projects'
});

This gives me the error:

XMLHttpRequest cannot load http://url/data.json. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.

And

default.html:1 Uncaught (in promise) gt {url: "http://url/data.json", ok: false, status: 0, statusText: "", headers: bt…}

Can someone help me with this?

Thanks in advance!

  • 1
    Adding that header on your end is not going to change anything. It's a response header on their end denying your request. You can get around it by setting up a server that consumes that API and allow access to that. – Marty Jun 06 '17 at 07:05
  • You are correct. Seems like the server that i'm trying to get from is denying any allow access. So i had to change to another server which did allow it. – Jonas Christensen Jun 06 '17 at 07:21

0 Answers0