D
D
dzenn2016-03-24 17:36:16
JavaScript
dzenn, 2016-03-24 17:36:16

What is my mistake when displaying json?

$( document ).ready(function() {
$.ajax({
   url: 'http://mylink.com',
   type: 'GET',
   dataType: 'json',
   crossDomain: true,
   success: function(data){
       console.log(data.object.array.id);
   },
  beforeSend: function (xhr) {
    xhr.setRequestHeader ("Authorization", "Token " + "mytoken");
},
});
});


ef190d9879044a8896f2e2075c147168.png

ONLY ID SHOULD BE DISPLAYED

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kovalsky, 2016-03-24
@dzenn

Do I need to output all id to the console ? If so, then maybe:

$( document ).ready(function() {
  $.ajax({
    url: 'http://mylink.com',
    type: 'GET',
    dataType: 'json',
    crossDomain: true,
    success: function(data){
      for (var i = 0, l = data.length; i < l; i++) {
        console.log(data[i].id);
      }
    },
    beforeSend: function (xhr) {
      xhr.setRequestHeader ("Authorization", "Token " + "mytoken");
    },
  });
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question