user1757452
user1757452

Reputation: 61

Getting a 'Undefined' list in JSON response

The JSON I'm requesting is an array within an array (I think) and looks like this:

"results": {
"collection1": [
  {
    "Inches": "1\"",
    "Resort": "Keystone",
    "index": 1,
    "url": "http://extras.denverpost.com/skireport/colorado/recentsnow.html"
  },
  {
    "Inches": "0\"",
    "Resort": "Breckenridge",
    "index": 2,
    "url": "http://extras.denverpost.com/skireport/colorado/recentsnow.html"
  },
  {
    "Inches": "0\"",
    "Resort": "Telluride",
    "index": 3,
    "url": "http://extras.denverpost.com/skireport/colorado/recentsnow.html"
  },

I am trying to display this information in a list, but I get an 'Undefined' result list with the following JQuery:

   $.ajax({
   url:"www.kimonolabs.com/api/5qtdkod0apikey=z6vewKq5SXBcF6Q6L17sQEJ8gaYMou0C",
   crossDomain: true,
   dataType: "jsonp",
  'success': function (response) {

  $(".panel-heading").html(response.name);
  //Puts the API name into the panel heading

  var collection = response.results.collection1;
  for (var i = 0; i < collection.length; i++){


     $(".list-group").append('<li class="list-group-item">' + 
     collection[i].resort.inches + '</li>');
   //when I just try to bring in either resort or inches I get an 'undefined' list-- when I try to add both (e.g resort.inches) I don't get any results
      }
     }
   });

What's the best way to define the resort and inches data and display it in the "list-group-item" list. Here's a fiddle: http://jsfiddle.net/6w0sdctg/

Upvotes: 0

Views: 224

Answers (1)

I wrestled a bear once.
I wrestled a bear once.

Reputation: 23379

1) When you're making a jsfiddle, you need to add jQuery by clicking on the gear icon in the top right corner of the javascript box.

2) you're getting an undefined because the URL you are requesting is not returning a jsonp response. put it in your browser and see. The reason, I gather from the docs on that website, is because it requires an API key, and you are not sending an API key.

Read more about it here.

Edit, after reading Barmar's comment, it looks like you're trying to send an API key, but it's not being sent becuase you're missing the ampersand before it. should be /?...&apikey=...

Upvotes: 0

Related Questions