Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="can-fixture demo">
<meta name="" content="" />
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
<ul id='out'>Loading</ul>
  <script src='https://rawgit.com/canjs/can-fixture/v0.2.1/dist/global/can-fixture.js'></script>
  <script src="https://code.jquery.com/jquery-2.1.4.js"></script>
</body>
</html>
 
// fixture code ----------
fixture("GET /todos", function(){
  return {
    data: [{id: 1, name: "dishes"},
           {id: 2, name: "lawn"}]
  }
});
// client code -----------
var xhr = new XMLHttpRequest();
xhr.addEventListener('load', function(){
  var data = JSON.parse(this.responseText);
  printTodos(data);
});
xhr.open('GET', "/todos");
xhr.send();
function printTodos(todosResponse) {
  var lis = todosResponse.data.map(function(todo){
    return "<li>"+todo.name+"</li>"
  });
  document.getElementById("out").innerHTML = lis.join("");
}
Output

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

Dismiss x