0

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/

  • 1
    Based on the object structure you posted, `collection[i].resort.inches` is undefined. You could do `collection[i].Resort` or `collection[i].Inches`. But `collection[i].Resort` is not an object containing a property called `inches`. – Jason P Dec 09 '15 at 20:29
  • Are you sure that web service supports JSONP? – Barmar Dec 09 '15 at 21:16
  • Did you copy the URL correctly in the question? There should be `?` before `apikey=`/ – Barmar Dec 09 '15 at 21:23
  • When I run your API request I get this "{"error":"Gone","message":"Sorry! We only provide access to the last 30 days of your data. If you'd like longer retention, please contact us at support@kimonolabs.com."}" - You need to run the crawl again. – Elvn Dec 11 '15 at 14:44
  • The crawls should be set up to run daily... i just ran it again, so it should work. – user1757452 Dec 11 '15 at 17:17
  • A quick test you can do is copy and paste the API request in your browser and the JSON should be returned. I still get the "Gone" message when I use the API you posted: http://www.kimonolabs.com/api/5qtdkod0?apikey=z6vewKq5SXBcF6Q6L17sQEJ8gaYMou0C – Elvn Dec 15 '15 at 23:55

1 Answers1

0

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=...

I wrestled a bear once.
  • 22,983
  • 19
  • 69
  • 116