vue.js $HTTP.GET return NULL PHP RESPONSE

551 views Asked by At

I'm trying to consume an API and the $ http.get only returns NULL. I call a PHP that returns a json

What nonsense am I doing?

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.1.7/vue.js"></script>
<script src="https://cdn.jsdelivr.net/vue.resource/1.0.3/vue-  resource.min.js"></script>
<div id="app">{{cervejarias}}</div>


new Vue({
el:'#beerApp',

data:{
cervejarias: null
},
methods:{
getChamados: function(){
    this.$http.get('listar_cervejarias.php').then(function(response){
        this.cervejarias = response.data;
    }, function(error){
        console.log(error.statusText);
    });
 }
},
 mounted: function () {
 this.getChamados();
 }


  });
1

There are 1 answers

0
user3007720 On

Consider adding:

header('Access-Control-Allow-Origin: *');

To your PHP pages.