Search code examples
javascriptjsongetjson

Why do I get an 'undefined' error when trying to read a JSON from an URL


I would appreciate it a lot if you guys could help me out with this problem.

I'm trying to read the JSON from this URL: https://aixtra.klinikum.rwth-aachen.de/rest_index.php but I only get an 'undefined' error. I'm able to read this JSON in the Google ARC Plugin and I can read other JSONs from other URLs with my code so I don't understand where the problem is.

This is my code:

    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    <script type="text/javascript">
    $(function() {
      $.getJSON("https://aixtra.klinikum.rwth-aachen.de/rest_index.php", function(response) {
        $.each(response.data, function(index, d) {
          $("#print_kurse").append("Datum: " + d.TERMIN + ", Kurs: " + d.kurs + ", von: " + d.von + ", bis: " + d.bis + "</br>");
        });
      }).error(function(jqXHR, textStatus, errorThrown) {
        alert("Error: " + jqXHR.responseText);
      });
    });
    </script>

    <div id="print_kurse"></div>

Any Ideas? Would appretiate it a lot!


Solution

  • This has to do with AJAX requests over HTTP/HTTPS. You are requesting content from an HTTPS source over HTTP. This blocked by the server you're trying to reach. Make sure you are requesting the data over HTTPS.