I'm unsure how I broke this; it was working previously but now is not. From within an HTML file, I'm making a POST call to a php file (which then grabs data from a REST API), but instead of returning any API data, what I get returned is the actual PHP code.
jQuery AJAX in HTML page:
$.ajax({
type: "post",
url: "api.php",
data: {code: event.data.node.id}
})
api.php:
<?php
$username='[my_username]';
$password='[my_password]';
$code = $_POST['code'];
$URL='https://services.onetcenter.org/ws/online/occupations/' . $code . '/details/';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$URL);
curl_setopt($ch, CURLOPT_TIMEOUT, 30); //timeout after 30 seconds
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); //get status code
$result=curl_exec ($ch);
curl_close ($ch);
echo $result;
?>
What I get returned appears to be a string of the PHP code above, rather than the result of the API call. What's going on here? If you need any more information, I'd be happy to help you help me!
EDIT: The second code excerpt was mislabeled as in an HTML file. In fact, the php is within api.php. Sorry!
echo $result;in the wrong place. The second time was because a coder leftreturn false;in the wrong place. And it was just a random place in the code both times.