Sfoglia il codice sorgente

Exercise 4 (challenge): use JSONP to load user's Github repositories on page load.

Frederic G. MARAND 9 anni fa
parent
commit
c054835420
1 ha cambiato i file con 12 aggiunte e 1 eliminazioni
  1. 12 1
      Chapter 6/06.js

+ 12 - 1
Chapter 6/06.js

@@ -1,7 +1,18 @@
 $(document).ready(function () {
   'use strict';
 
-  $('#dictionary').load('exercises-content.html div');
+  $.getJSON('http://api.github.com/users/FGM/repos' + '?callback=?', function (response) {
+    var html = '';
+    var items = ['<ul>'];
+    $.each(response.data, function (entryIndex, entry) {
+      var name = entry.name;
+      var url = entry.html_url;
+      items.push('<li><a href="' + url + '">' + name + '</a></li>');
+    });
+    items.push('</ul>');
+
+    $('#dictionary').html(items.join(''));
+  });
 
   $('.letter').hover(function () {
     var $this = $(this);