Connecting Droplet to my front end

July 23, 2015 1.8k views
PHP FAQ LAMP Stack DigitalOcean

So my front end is hosted by AWS, just a simple s3 bucket with HTML, CSS, and JavaScript files on there.

The JavaScript files on my front end make XMLHttpRequests, how should I word those to reach out to my droplet? Say my URL is 55.55.555.555 and the file I need is file5.php.

here is what I have been using:“POST”,“http://55.55.555.555/file5.php”,true);

It is not working, I get this feedback:

XMLHttpRequest cannot load http://55.55.555.555/file5.php. No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin 'null’ is therefore not allowed access. The response had HTTP status code 404.

Anybody know what I should be doing differently?

1 Answer

You need to set an Origin allow rule in the headers of your application. in the file file5.php you can add this

header(“Access-Control-Allow-Origin: *”);

Have another answer? Share your knowledge.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!