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 :

$var = "Mountain";
echo json_encode($var);
echo $var;

<div id="Window">

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;
};"get", "line_chart V14.php", false); //True pour que l'exécution du script continue pendant le chargement, false pour attendre.

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

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