Commits

Alexander Dahl committed 0573e6e Draft

ch08: get runners data with ajax request

  • Participants
  • Parent commits 3ce7473

Comments (0)

Files changed (2)

page295/finishers.xml

+<?xml version="1.0" encoding="utf-8"?>
+<finishers>
+	<runner>
+		<fname>John</fname>
+		<lname>Smith</lname>
+		<gender>m</gender>
+		<time>25:31</time>
+	</runner>
+	<runner>
+		<fname>Jacob</fname>
+		<lname>Walker</lname>
+		<gender>m</gender>
+		<time>25:54</time>
+	</runner>
+	<runner>
+		<fname>Mary</fname>
+		<lname>Brown</lname>
+		<gender>f</gender>
+		<time>26:01 </time>
+	</runner>
+	<runner>
+		<fname>Jenny</fname>
+		<lname>Pierce</lname>
+		<gender>f</gender>
+		<time> 26:04</time>
+	</runner>
+	<runner>
+		<fname>Frank</fname>
+		<lname>Jones</lname>
+		<gender>m</gender>
+		<time>26:08</time>
+	</runner>
+	<runner>
+		<fname>Bob</fname>
+		<lname>Hope</lname>
+		<gender>m</gender>
+		<time>26:38</time>
+	</runner>
+	<runner>
+		<fname>Jane</fname>
+		<lname>Smith</lname>
+		<gender>f</gender>
+		<time> 28:04</time>
+	</runner>
+	<runner>
+		<fname>Ryan</fname>
+		<lname>Rice</lname>
+		<gender>m</gender>
+		<time>28:24</time>
+	</runner>
+</finishers>

scripts/page295.js

     $('#updatedTime').html(curr_hour + ":" + curr_min + ":" + curr_sec + " " + a_p );
 }
 
-$(document).ready(function(){
-    getTime();
+function getXMLRacers() {
+    $.ajax({
+        url:        "page295/finishers.xml",
+        cache:      false,
+        dataType:   "xml",
+        success:    function(xml){
+            $('#finishers_m').empty();
+            $('#finishers_f').empty();
+            $('#finishers_all').empty();
+
+            $(xml).find("runner").each(function(){
+                var info = '<li>Name: ' + $(this).find("fname").text() +
+                    ' ' + $(this).find("lname").text() + '. Time: ' +
+                    $(this).find("time").text() + '</li>';
+                if ( $(this).find("gender").text() == "m" ) {
+                    $('#finishers_m').append(info);
+                } else if ( $(this).find("gender").text() == "f" ) {
+                    $('#finishers_f').append(info);
+                } else { }
+                $('#finishers_all').append(info);
+            });
+
+            getTime();
+        }
+    });
+}
+
+jQuery(document).ready(function(){
+    getXMLRacers();
 });