I am trying to send a form data using POST method to a PHP page. I want to read that POST value in jquery. Below is the code.

**HTML:**

```
<form method="post" action="test.php">
  <input name="username" id="username"></input>
  <input type="button"></input>
</form>

```

**PHP:**

```
<?php
<script type="text/javascript">
      alert(<?php $uname ?>);
</script>

$uname = $_POST["username"];
echo $uname;
?>

```

Its not working. 
How can I do the same in an ajax request (instead of a form) like below:

```
$.ajax({
    type: "POST",
    url: "test.php", 
    data: {username: $('#username').val()}, 
    success: function(serverResponse){
        $('#Attach').html(serverResponse);
    }
});

```