Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<script src="//code.jquery.com/jquery-2.1.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mustache.js/0.8.1/mustache.min.js"></script>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
  <script id="template" type="x-tmpl-mustache">
    {{#hosts}}
      <li>{{host_name}}</li>
    {{/hosts}}
  </script>
  <ol class="results"></ol>
</body>
</html>
 
.error {
  color: red;
  font-weight: bold;
}
 
// Mustache loops: 
// Get the names of the people running the top 25 most expensive
// AirBnB rentals in New York using CartoDB's SQL API and list them.
$(document).ready(function () {
  // Use jQuery to call the SQL API
  $.getJSON('https://eric.cartodb.com/api/v2/sql?q=SELECT * FROM airbnb2 ORDER BY price DESC LIMIT 25')
    
    // When it's done it will pass the parsed response in data
    .done(function (data) {
      var template = $('#template').html(); 
      var context = {
        hosts: data.rows
      };
      var output = Mustache.render(template, context);
      $('.results').append(output);
    })
   
    // This function is called if the API call fails
    .fail(function (resp) {
      $('body').append(
        $('<div></div>')
          .text(resp.responseJSON.error[0])
          .addClass('error')
      );
    });
});
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
ebrelsfordpro
0viewers