Currently, I am working on developing the website layout for . Most of the data retrieval and display have been successful so far.
However, when attempting to filter my search results to show only stop names associated with Subways, I encountered some errors. You can find the JSON page related to this issue at . Specifically, when trying to access stops with the route name 'Yonge-University-Spadina Subway
', I received an error message stating '
Uncaught TypeError: Cannot call method 'equals' of undefined
'. I also attempted using the '===
' operator without success. Despite searching extensively online for a solution, I have not been able to resolve this issue. As a beginner in JavaScript, it is possible that I overlooked something crucial in my code. Here is the portion of my code causing the problem:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(document).ready(function(){
// retrieving the data.
$.getJSON("http://myttc.ca/finch_station.json?callback=?", function(data){
//Storing the string in variable.
var subway="Yonge-University-Spadina Subway";
console.log(data);
//Displaying the station name first in a div called "stations" in the body.
$("#stations").append('Station: ' + data.name + '<br/>');
//Iterating through the stops array to display each stop name
$.each(data.stops, function(i,stopz){
$("#stations").append(' Stop: ' + stopz.name + '<br/>');
//This is my problem area.Not able to compare the routes.name to the string.
if(stopz.routes.name === subway) {
$.each(stopz.routes, function(i,routez) {
//Displaying the Departure time and shape of the stops.
$.each(routez.stop_times, function(i,timez) {
$("#stations").append(' Departure-time: ' + timez.departure_time + ' || Shape: ' + timez.shape + '<br/>');
});
});
}
});
});
});
</script>
</head>
<body>
<div id="stations">
</div>
</body>
</html>
I would greatly appreciate any assistance provided. Thank you.