G
G
game8022017-01-18 15:19:13
JSON
game802, 2017-01-18 15:19:13

How to send and receive JSON data correctly?

Good afternoon dear experts. Faced the following problem:
On the server side, I form a json object as follows:

$arr = array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5);
echo json_encode($arr);

As expected, I create the head:
header("Content-Type: application/json;charset=utf-8");

On the client side, I accept the data using Vue.js like this ( vue-resource ):
fetchData: function () {
  this.$http.get(this.apiURL).then(function (response) {
    console.log(response);
    this.items = response.data;
  }, function (error) {
    //error
  })
}

As a result, I get the following data...:
69017bea91864f5fa6b13df7c1834389.png
Instead of Object, Response arrives... How to fix this problem? Thanks a lot for any help!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Melnikov, 2017-01-18
@game802

this.$http.get(this.apiURL)
    .then(function (response) {
      return response.json();
    })
    .then(function(obj) {
      console.log(obj.data)
    })

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question