I'm trying to print out the value of a PHP variable in the browser's console by using jQuery and AJAX. The $.ajax
function seems to be the way. The main problem is that I don't know what am I supposed to assign to the data
parameter and what to pass as the success
function parameter.
This is the PHP file:
<?php
$foo = "Hello, World!";
?>
And this is my attempt at AJAX:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Lorem ipsum</title>
<meta charset="utf-8">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body>
<script>
$.ajax({
url: "../scr/main.php",
type: "POST",
data: /* What am I supposed to put here? */
success: function(/* And what am I supposed to put here? */) {
console.log(/* The value of $foo */);
}
});
</script>
</body>
</html>