Trying to pass 2 JS variables to my PHP page using AJAX. One variable is just time, and the other is a string of user input. I don't know how to get the user input from the modal form, I want to submit those variables in a GET and write them to a leaders.txt file.
var d = new Date();
var t = d.getTime();
var rec = (t - time)/1000
alert("Time = " + rec + " seconds!");
var modal = document.getElementById("userName");
$(modal).modal('show');
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET","index.php?time=" + rec, true);
xmlhttp.send();
<div class="modal fade in" id="userName" tabindex="-1" role="dialog"
aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"
aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">Add your name to the leader board!</h4>
</div>
<div class="modal-body">
<form method="get" action="index.php" role="form">
<div class="form-group">
<label for="usr">Arcade Name:</label>
<input type="text" class="form-control" id="usr">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
</div>
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
</div>
<?php
$time = $_GET["time"];
if($time != ""){
$name = $_GET["name"];
console.log($time + $name);
file_put_contents("leader.txt", $name.':'.$time."\n", FILE_APPEND);
}
?>