simple $.post() problem

simple $.post() problem

i am totally confused about the function i made:

my js inside <head> tag, after the jquery.js:

  1. <script type="text/javascript">
  2. $(document).ready(function(){
  3.     function addasfriend(){
  4.         var n = $(this).attr('id');
  5.         $.post('test.php',{f:n},function(r){
  6.             alert("Newly added: " +r);
  7.         });
  8.     }
  9. });
  10. </script>

my html <body> (ID tag = name_is_here, supposively the name of a person)
  1. <a href="#" id="name_is_here" onclick="addasfriend();">Add as friend</a>

the test.php page

  1. <?php
  2. if(isset($_POST)){
  3.     echo $_POST['f'];
  4. }
  5. ?>
why isn't working?

- any suggestion is highly appreciated. thanks!