Parcourir la source

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

Frederic G. MARAND il y a 8 ans
Parent
commit
c054835420
1 fichiers modifiés avec 12 ajouts et 1 suppressions
  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);