I have a php file, content.php, that is currently being loaded in the browser:
<html>
<head>
<title>Content</title>
<script src="content.js"></script>
</head>
<body>
<?php
if ( isset($_POST["status"]) && ($_POST["status"] === 1) ) {
?>
Content for users with status 1
<?php
} else {
?>
Content for users with different status
<?php
}
?>
</body>
</html>
What I want to do, is set the
$_POST["status"]
variable from within
content.js
I have thought about using a hidden html form and clicking the submit button through javascript, but that doesn't really seem like an elegant solution.
I have also thought about using an XMLHttpRequest, the problem being that I haven't found a way to send the data to the currently viewed/loading page through an XMLHttpRequest.
I am using no extra libraries, only javascript and php.
Is there a more elegant solution to my problem the a hidden html form?