Send var from PHP to JS with Ajax

I try to send a var from a PHP scrit to a js scrip with Ajax but i am not sure that this is working and so i have tried to have it in the console log but i get this error :
Capture d’écran 12-11-2022 18.08.31

My php script is as following :

<?php
$var = "Mountain";
echo json_encode($var);
echo $var;
?>

<div id="Window">
<script 
src="TestAjax9.js">
</script>

and the script TestAjax9.js is as following :

var requete = new XMLHttpRequest();
requete.onload = function() {
 //La variable à passer est alors contenue dans l'objet response et l'attribut responseText.
 var variableARecuperee = this.responseText;
};
requete.open("get", "line_chart V14.php", false); //True pour que l'exécution du script continue pendant le chargement, false pour attendre.
requete.send();
console.log("AU",variableARecuperee);

I’m afraid you’re asking this question in the wrong forum. I recommend to try Stack Overflow or other more specialized forums.

If your question were about sending data from PHP to a notebook, then it would be as simple as consuming your local endpoint with fetch(), for example:

data = (await fetch(`http://localhost:8080/my-api.php?${
  new URLSearchParams({mykey: "myvalue"}) // turns into the query string
}`)).json()

Hi ok thanks for your answer. I asked on other forum.