I know this question has been asked a lot and this is going to get flagged as duplicate, but I need the code because I can't get my head around any of it.
I have a variable x in my js file. I want that in my php file. Here's the messed up code that I have:
index.js-
var x=5;
$.ajax({
type: 'POST',
url: 'form.php',
data: {'variable': x },
});
form.php-
<?php $myval = $_POST['x'];
echo $myval;?>
Also, do I need to connect with the server first or something for the ajax call? Thanks in advance.
?>and are probably better off without it, might get new line of returned value as is.