Monday, March 4, 2019
Ajax Simple Example
$.ajax(
'https://api.wmata.com/Rail.svc/json/jStations?LineCode=BL&api_key=' + key
)
.done(function(data) {
console.log(data);
var stationList = new Array();
console.log('Length: ' + data.Stations.length);
for (var x = 0; x < data.Stations.length; x++) {
console.log(x);
var name = data.Stations[x].Name;
var id = data.Stations[x].Code;
var thisStation = new Station(name, id);
stationList.push(thisStation);
}
for (var x = 0; x < stationList.length; x++) {
var out = "<option value='" + stationList[x].stationId + "'>";
out += stationList[x].stationName;
out += '</option>';
document.getElementById('stationListSelector').innerHTML += out;
}
})
.fail(function() {
alert('error');
});
Labels:
ajax
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment