2

I have created an Apache server on an EC2 instance that I am using to host a mySQL database and some PHP scripts to access that database. I have installed what I think are the all of the required dependencies on the Apache server, to the point where when I write a PHP script and access it via a web browser using the address bar, the PHP script runs, queries my database and returns the correct information to the web browser.

However, the goal of the scripts is to be used by a Javascript application to access the database via AJAX, specifically a Captivate course. When I try to use AJAX to access the scripts, nothing happens. Captivate gives very little information about error logging, so I have tried using other services to check my javascript to make sure it is working, such as jsfiddle.net, but it seems like the Javascript is not the problem. Here is my code:

function httpGet(theUrl)
{
    var xmlHttp = new XMLHttpRequest();
    xmlHttp.open( "GET", theUrl, false ); // false for synchronous request
    xmlHttp.send();
    alert(xmlHttp.responseText);
}

My goal is not necessarily to use Alert to post the code to the screen, I'm using it just to check if I got anything back in the first place. theUrl leads to a php script on the other end called simpleecho.php:

<?php
    echo "test";
?>

I have more complicated PHP scripts, but they also all work in browser. If I go to theUrl in an address bar of a web browser, I see "test". I have tried changing from Async requests to Sync, I am certain that Captivate's javascript can use jQuery related code, I have tried like 8 different ways of sending the AJAX request as both POST and GET, but I'm not sure what I am missing. My gut says there is something wrong configured with the Apache server that is keeping it from responding to specifically requests outside of my address bar, but I don't know enough about configuring my httpd.conf file to know what I am looking for.

Any and all tips and learning is appreciated!

360Talon
  • 31
  • 2
  • Have you opened the browser's developer tools? Check the console for error messages and observe the AJAX request/response there. – Jay Blanchard Apr 21 '20 at 16:45
  • Apache configuration will not stop a request unless there is a CORS error. – Jay Blanchard Apr 21 '20 at 16:45
  • @JayBlanchard Thanks for the tip about using the developer tools, on jsfiddle.net the request is stopped because of "loading mixed active content". From what I am reading, this appears to be because I am doing a XMLHttpRequest over http and not https. However, I am unsure how I would be able to change my Apache server to be able to serve HTTPS addresses instead of just HTTP. Do you know anything about this? – 360Talon Apr 21 '20 at 16:58
  • Yes - you will need at the very least a self-signed certificate to allow SSL on your Apache server. So that is where your next area of research should be. – Jay Blanchard Apr 21 '20 at 17:01

1 Answers1

1

The answer to this question was that I was not allowed to use HTTP to communicate with the apache server, and it has to be secured with SSL to use HTTPS. I tried using a Self-Signed certificate, but the self-signed version was also not allowed for use with a Captivate Course.

360Talon
  • 31
  • 2