0

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!

  • Please show us the entire error please :) – Sapikelio Apr 26 '16 at 09:00
  • I only get an alert with the following text: Unter aixtra.rwth-aachen.de wird Folgendes angezeigt: Error: Sorry, the 'undefined' was in another case. Been trying it for 2 days now and tryied so many possibilities and got nothing so far – Alexander Hoffmann Apr 26 '16 at 09:03
  • Maybe `No 'Access-Control-Allow-Origin' header is present on the requested resource.`? – Paul Apr 26 '16 at 09:04
  • @Paul this is the header and echo from the page generating the url: `header('Content-type: application/json; charset=utf-8'); echo json_encode($message, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHED);` – Alexander Hoffmann Apr 26 '16 at 09:07

1 Answers1

1

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.

Starfish
  • 3,344
  • 1
  • 19
  • 47
  • 1
    Has to be as the code works fine when requesting from the same Plunkr URL: (https://plnkr.co/edit/mUtLCS) – PeterS Apr 26 '16 at 09:08
  • @Patrick2607 how could I do that? Is it something I would have to add to my code? – Alexander Hoffmann Apr 26 '16 at 09:40
  • Did you develop the API yourself and do you have access to modify the code? – Starfish Apr 26 '16 at 09:56
  • Now I manged to change the URL to http:// and it still doesn't work. Yes, I developed the API, so I can change it as I need. Why? Do you have any Ideas? By the way: the link changed a bit to: [link](http://aixtra.klinikum.rwth-aachen.de/cms/rest_index.php) – Alexander Hoffmann May 04 '16 at 14:45
  • You need to activate Access-Control-Allow-Origin on your server. Read more about that subject here: http://stackoverflow.com/questions/10636611/how-does-access-control-allow-origin-header-work – Starfish May 04 '16 at 15:00