I have built a microcontroller, that collects various information from my house.
The build-in webserver returns this information in a JSON-string when requested via port 84. It all works nicely!
My website makes a http request to the microcontroller to get data and present it on a html page.
The html page with the javascript looks like this (simplified):
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Test</title>
<script type="text/javascript"> var myJson = "http://mycontroller.com:84/fields.json";
window.onload = getJSON();
function getJSON() { var request = new XMLHttpRequest();
request.open("GET", myJson, true);
request.send(null);
request.onreadystatechange = function () {
if (request.readyState == 4) {
if (request.status == 200) {
document.getElementById('st').innerHTML = "Data received</br>"+request.responseText;
} else if (failure) {
document.getElementById('st').innerHTML = "Request failed - " + request.status + ": " + request.statusText;
}
}
}
}
</script>
</head>
<body>
<div id="st"></div>
</body>
</html>
Yes – there is a cross-domain problem – but this has been solved and is outside this question. I have left this out of the code to simplify.
Now to my problem:
The code works without problem. As it can be seen from the url, I use port 84 on the microcontroller. I wanted to hide this, and created a web-hop on my DDNS (dyndns.com). This will redirect
'http://mycontroller.com:84' to 'http://mywebhob.dyndns.org'
I can test it by putting the two urls ( + '/fields.json') into my browser and in both cases, I get the json data back.
The two url’s are:
'http://mycontroller.com:84/fields.json' (same as in the code) and
'http://mywebhop.dyndns.org/fields.json'
HOWEVER!
If I change the value in the code of 'var myJson =' from the old url to the new url, the http-request return an ok response but no data????
The problem is caused by using a web-hop that redirects from a url with port to an url without a port – but why?????
Hoping for a smart answer (and maybe even a solution!)
Regards
Erik