Jump to content


Photo

Ch8, P308 - Bad Code


  • Please log in to reply
5 replies to this topic

#1 LongLiveCHIEF

LongLiveCHIEF

    Active Member

  • Members
  • PipPip
  • 20 posts

Posted 27 February 2012 - 11:51 PM

On page 308, you construct the getXMLRacers() function, but they never tell you to call it. As a result, when you try to run the test drive on page 309, you will only see white in the display area for each tab. All you need to do is add one line of code above the function definition:

getXMLRacers();

function getXMLRacers(){
//remaining code from page 308

Here's the entire js script:

$(document).ready(function(){
getXMLRacers();
function getXMLRacers(){
$.ajax({
url: "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();
}
});
}


function getTime(){
var a_p = "";
var d = new Date();
var curr_hour = d.getHours();

(curr_hour < 12) ? a_p = "AM" : a_p = "PM";
(curr_hour == 0) ? curr_hour = 12 : curr_hour = curr_hour;
(curr_hour > 12) ? curr_hour = curr_hour - 12 : curr_hour = curr_hour;

var curr_min = d.getMinutes().toString();
var curr_sec = d.getSeconds().toString();

if (curr_min.length == 1) { curr_min = "0" + curr_min; }
if (curr_sec.length == 1) { curr_sec = "0" + curr_sec; }

$('#updatedTime').html(curr_hour + ":" + curr_min + ":" + curr_sec + " " + a_p );
}
});

#2 gumghandi

gumghandi

    New Member

  • Members
  • Pip
  • 3 posts

Posted 04 June 2012 - 12:56 PM

I've plugged in your code and It still doesn't work! I've tried running it off my lap top and from my website, and it still doesn't work. I've spend hours looking at this code and I believe that this part of the code isn't working. Can anyone help me with this? I've had good luck with chapters 1 throught 7.

$(xml).find("runner").each(function() {
var info=$(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);
});

Edited by gumghandi, 04 June 2012 - 01:06 PM.


#3 gumghandi

gumghandi

    New Member

  • Members
  • Pip
  • 3 posts

Posted 05 June 2012 - 03:52 PM

I found out what was wrong. I have a line break at the top of my xml file.

#4 gumghandi

gumghandi

    New Member

  • Members
  • Pip
  • 3 posts

Posted 05 June 2012 - 04:01 PM

I've discovered a new problem. The example from chapter 8 doesn't work in Chrome. Does anyone know why?

#5 Elisabeth_H

Elisabeth_H

    New Member

  • Members
  • Pip
  • 2 posts

Posted 17 October 2012 - 01:15 AM

Thanks for the hint with Chrome! I also spent hours trying to figure out what was wrong. Got suspicious when I tried to run the "end" example and that didn't work either...

#6 Elisabeth_H

Elisabeth_H

    New Member

  • Members
  • Pip
  • 2 posts

Posted 17 October 2012 - 01:30 AM

I've discovered a new problem. The example from chapter 8 doesn't work in Chrome. Does anyone know why?


Had the same problem as well (see above), but it turned out I was just too quick and overlooked this important information.
On page 309 "Test Drive" they ask you to make sure to run the code through your web server. As soon as you do that there is no problem with Chrome anymore.

Edited by Elisabeth_H, 17 October 2012 - 01:31 AM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users