I am currently trying to output data from my php file into javascript, but I get this error:
(https://i.sstatic.net/9QL2o1bK.png)
script.js file:
fetch('./index.php', {
method: 'post'
}).then(response => {
return response.text();
}).then(response => {
document.getElementById("status").innerHTML = response
});
index.php file:
<?php
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
return $ip;
?>
I am currently trying to output data from my php file into javascript, I was expecting the php file I fetched to output the ip address, but that didn’t work and return 405 error.
New contributor
Kevin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.