From 04333c456b569748dc9b669c64cbd4c0fce18726 Mon Sep 17 00:00:00 2001 From: tmeissner Date: Thu, 28 Feb 2013 12:53:30 +0100 Subject: [PATCH] * remove tag parentheses (<, >) from the response with the replace() method * check for the origin of the url (with or without www) to select the suitable ajax url to fullfill the same origin policy --- scripts/haltestellen.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/scripts/haltestellen.js b/scripts/haltestellen.js index d4bfed8..80d5e14 100644 --- a/scripts/haltestellen.js +++ b/scripts/haltestellen.js @@ -2,10 +2,6 @@ // set to 1 to enable debug log var DEBUG; -// server url -//var serverUrl = "http://widgets.vvo-online.de/abfahrtsmonitor/"; -var serverUrl = "http://goodcleanfun.de/cgi-bin/"; - // xmlhttp object function function getHTTPObject() { @@ -70,6 +66,14 @@ function ajaxCall(dataUrl, outputElement, callback, responseType) { // debug log if (DEBUG === 1) {console.log("anonymous function");} + // server url + var origin = window.location.origin.indexOf("www.goodcleanfun.de"); + if (origin === -1) { + var serverUrl = "http://goodcleanfun.de/cgi-bin/"; + } else { + var serverUrl = "http://www.goodcleanfun.de/cgi-bin/"; + } + // get the search form var searchForm = document.getElementById("search-form"); @@ -88,7 +92,6 @@ function ajaxCall(dataUrl, outputElement, callback, responseType) { // get output area var target = document.getElementById("output"); var hstName = document.getElementById("q").value; - //var hstUrl = serverUrl + "Abfahrten.do?ort=dresden&hst=" + hstName; var hstUrl = encodeURI(serverUrl + "abfahrtsmonitor.py?ort=dresden&hst=" + hstName); ajaxCall(hstUrl, target, function(data) { @@ -99,6 +102,7 @@ function ajaxCall(dataUrl, outputElement, callback, responseType) { data = data.replace(/\],\[/gi, '#'); data = data.replace(/\(.+?\)/gi, ''); data = data.replace('ß', 'ss'); + data = data.replace(/<(.+?)>/gi, '$1'); data = data.slice(3,-3).split("#"); // debug log