I refer to this question: Javascript value to PHP with Jquery
I tried with below code in file named a.php:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script type="text/javascript">
var ms = 9000;
function test()
{
$.ajax({ url: "a.php",
data: {"test":ms},
type: 'get',
success: function(output) {
$('#testing').html(output);
}
});
}
test();
</script>
<?php
$ms = $_GET["test"];
echo "I am getting below value:";
echo $ms;
?>
Then I point browser to http://localhost/learn/a.php but got error message & value of $ms is not shown as expected:
( ! ) Notice: Undefined index: test in C:\wamp\www\learn\a.php on line 17
$ms = $_GET["test"]; <-- The line 17 in a.php
I tried another simpler code (b.php) below:
<script src="js/jquery.min.js"></script>
<script type="text/javascript">
var ms = 3000;
$.get("http://localhost/learn/b.php", { "test": ms } );
</script>
<?php
$ms = $_GET["test"];
echo $ms;
?>
Then I point browser to http://localhost/learn/b.php but got similar error message & no value of $ms displayed:
( ! ) Notice: Undefined index: test in C:\wamp\www\learn\b.php on line 7 Below is code of line 7 $ms = $_GET["test"];
Please advice. Thanks.