passing javascript variable to php and redirecting page to php file
how to pass javascript variable to a php file using post method
I want that after click my page should be directed to r.php and it should display the passed js variables from client side
here is the code
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script>
$("#text-id").click( function () {
$.ajax({
type: 'post',
url: 'r.php',
data: {
source1: "some text",
source2: "some text 2"
}
});
});
</script>
</head>
<body>
<div>
<a href="#" id="text-id">Send text</a>
</div>
</body>
</html>
PHP CODE
<?php
echo "hello";
$e=$_POST['source1'];
echo $e;
?>