diff --git a/scripts/haltestellen.js b/scripts/haltestellen.js index 76ff614..fc5fcbf 100644 --- a/scripts/haltestellen.js +++ b/scripts/haltestellen.js @@ -1,6 +1,8 @@ // variable to en-/disable debug // set to 1 to enable debug log -var DEBUG; +if (DEBUG === undefined) { + var DEBUG = 1; +} @@ -10,14 +12,15 @@ var DEBUG; //variable definitions var serverUrl = gcf.getCgiBinPath(), // the url of the cgi-bin folder with the scripts we call with the ajaxCall() function + input = document.getElementById("input"), target = document.getElementById("output"), // get the html area where we print out the data searchForm = document.getElementById("search-form"), // get the search form + lastHst, haltestelle; // object with methods to get and process the data // debug log if (DEBUG === 1) {console.log("anonymous function");} - // haltestelle object haltestelle = { @@ -33,8 +36,10 @@ var DEBUG; var hstName = document.getElementById("q").value, hstUrl = encodeURI(serverUrl + "abfahrtsmonitor.py?query=abfahrten.do&ort=dresden&hst=" + hstName); + lastHst = hstName; + // get the data from the server with an ajax call - gcf.ajaxCall(hstUrl, target, this.processAbfahrten, "text"); + gcf.ajaxCall(hstUrl, target, haltestelle.processAbfahrten, "text"); }, @@ -48,13 +53,14 @@ var DEBUG; var i, y, htmlOutput, + htmlInput, entry, dataLength; // process of response only if it's not empty if (data.indexOf("[]") !== -1) { // there was an empty response - this.getHaltestellen(); + haltestelle.getHaltestellen(); } else { @@ -68,6 +74,9 @@ var DEBUG; dataLength = data.length; + htmlInput = ""; + htmlInput += ""; + // generate table header htmlOutput = "
unbekannte Haltstelle, bitte erneut versuchen
"; + target.innerHTML = htmlOutput; + } else { // replace useless chars & split string into array @@ -154,28 +165,26 @@ var DEBUG; dataLength = data.length; // generate table header - htmlOutput = "