I am trying to post a variable from javascript to the same php page. Here is the code:
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/jquery-ui.min.js"></script>
</head>
<body>
<?php echo 'Result is '; if (isset($_GET['testing'])) { echo $_GET['testing']; } ?>
<?php $thisPage = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; ?>
<script>
$(document).ready(function() {
$('#testing123').on('change',function () {
var testing = "confirmed";
$.ajax({
type: "GET",
url: "<?php echo $thisPage; ?>",
data: testing,
success: function() { $('#showresult').html("success"); }
})
});
});
</script>
<form>
<select id="testing123">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
</form>
<div id="showresult"></div>
</body>
</html>
I have also tried using POST but doesn't pick up in php. Also tried having a separate php file and using include_once() and still doesn't work.
Am I missing a file to load in?
data: { testing: testing },successfunction of the call, just a static string.