I can’t fetch from a php file to javascript

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 was expecting the php file I fetched to output the ip address, but that didn’t work and return 405 error.