Kaynağa Gözat

Listing 6.20. $.getJSON() for JSONP.

Frederic G. MARAND 9 yıl önce
ebeveyn
işleme
fcb39e9567
1 değiştirilmiş dosya ile 28 ekleme ve 0 silme
  1. 28 0
      Chapter 6/06.js

+ 28 - 0
Chapter 6/06.js

@@ -93,6 +93,34 @@ $(document).ready(function () {
     });
   });
 
+  var url = 'http://examples.learningjquery.com/jsonp/g.php';
+  $('#letter-g a').click(function (event) {
+    event.preventDefault();
+    $.getJSON(url + '?callback=?', function (data) {
+      var html = '';
+      $.each(data, function (entryIndex, entry) {
+        html += '<div class="entry">';
+        html += '<h3 class="term">' + entry.term + '</h3>';
+        html += '<div class="part">' + entry.part + '</div>';
+        html += '<div class="definition">';
+        html += entry.definition;
+        if (entry.quote) {
+          html += '<div class="quote">';
+          $.each(entry.quote, function (lineIndex, line) {
+            html += '<div class="quote-line">' + line + '</div>';
+          });
+          if (entry.author) {
+            html += '<div class="quote-author">' + entry.author + '</div>';
+          }
+          html += '</div>';
+        }
+        html += '</div>';
+        html += '</div>';
+      });
+      $('#dictionary').html(html);
+    });
+  });
+
   var $loading = $('<div id="loading">Loading...</div>')
     .insertBefore('#dictionary');