Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Feb 2011
    Thanked 0 Times in 0 Posts

    Problem with web-hop/redirect in http request

    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">
    <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.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;
    <div id="st"></div>

    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


    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!)


  2. #2
    Senior Coder
    Join Date
    Dec 2010
    Thanked 570 Times in 563 Posts
    One thing (which is clearly not related to the problem but still wrong)
    window.onload = getJSON;


Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts