Ajax发布数据

I have a javascript file that I want to send data from. I tried using $.ajax and $.post but neither seem to be sending the data to my index.php file.

script.js

$.post( "index.php", { over: 'yes' } ).done(function( data ) { alert("success"); });

//AND

$.ajax({
  url: "index.php",
  type: "POST",
  data: {over: "yes"},
  success: function(data){ alert("success"); },
});

Both methods receive the success message but neither are echo'ed in my index.php file

echo $_POST['over'];

What am I doing wrong? Thank you