Thought I'd try and pass data and get it to return, a bit lost. This is what I've tried

function getAddress(){
	const postalcode = this.value;
	fetch('locations.php').then(response => response.json()).then(postalcode => console.log(postalcode));
}
$postalcode = $_POST['postalcode'] ?? '';


if (isset($postalcode)) {
	
header('Content-type: application/json');
return json_encode($postalcode);
}

    I'm guessing you want to echo/print/otherwise output the JSON, not just return it.

    Write a Reply...