Javascript fetch fails to call localhost

I cannot let javascript fetch a localhost

contentAPI.php

<?php
echo 'en';
?>

curl call

curl http://localhost:8000/CONTENT/contentAPI.php

curl result

en

javascript call

fetch("http://localhost:8000/CONTENT/contentAPI.php")
        .then(function(response) {
            return response.text();
        })
        .then(function(responseText) {
            alert(responseText);
        })
        .catch(function(err) {
            alert(err);
        });

javascript result

TypeError: Failed to fetch

Any help?