I am trying to use cURL to request from an API and dynamically change my website. Normally I would just use AJAX, but I would need to use a proxy server to overcome cross-domain restrictions since I don't own the API. I set up this very simple code snippet to see if I could get the jQuery .load
to work.
<!DOCTYPE html>
<html>
<head>
<link type="text/css" rel="stylesheet" href="static/style.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js">
</script>
<script type="text/javascript" src="static/script.js"></script>
<title>
Load Test
</title>
</head>
<body>
<?php
echo "php is working"
?>
<div id="loadContent">
<button id="load">Load Test</button>
</div>
<script>
console.log(<?php echo '"Test"' ?>)
$(document).ready(function(){
$("#load").click(function(){
console.log("Load Started");
$("#loadContent").load('static/curl.php')
});
});
</script>
</body>
</html>
curl.php was just a test and at first included just:
<?php
echo "Hello World";
?>
There was no error thrown, but the PHP did not run. I am very new to PHP, but I know that it runs before anything else is loaded and is replaced by simple HTML. I thought that it might be replacing it before I call .load
, but it would still print "Hello World". I replaced the PHP with some HTML and it worked. I don't know enough about PHP to really debug this by myself because everything I've seen has said that this should work.