Self Answer
I have a script that is supposed to use AJAX to retrieve a video from Youtube, but, it requires AJAX to grab a PHP file. This PHP file needs Javascript variable to work, however, I could not seem to find a way to do this on this website. I found a way do to it with Jquery on this Qoura question.
But if you don't want to go there for whatever reason(I made some adjustments to the PHP code because it was created very poorly), to make a Javascript variable a PHP variable, you would use this (I'm not incredibly skilled with jQuery at all so I won't attempt to explain it, and also, keep in mind that these are just basic examples, this easily can be abstracted in multiple ways)
Jquery:
var username=$('input').val();
$.ajax({
url:'link_to_php_file',
method:'get',
data:{name:username},
success:function(data)
{
alert("Success");
},
error:function(data)
{
alert("error");
}
});
and the PHP for this is
PHP:
<?php echo $_GET['username']; ?>
Making a PHP variable into a Javascript variable is much simpler, however, is not a replacement for the above.
PHP
<?php echo "<script>showname('" . $_GET['username'] . "')</script>"
JavaScript
<script>
function showname(username) {
alert(username);
};
</script>