I just started studying PHP and Ajax and I can't figure out how to bring a single variable from PHP file to my html file using Ajax. Can you please explain me how it works?
So far I understood that you create the request:
var xhttp = new XMLHttpRequest();
And that you send it to the server:
xhttp.open("GET", "demo_get.php", true);
xhttp.send();
Then you get the data from the PHP file using
xhttp.responseText
Now, I only want to send a variable from the server, for example
$name = "John"
How should my php code look like in order to send only that specific variable?