sorry if my title is unclear but I'm not sure how exactly to form the question/problem. So, I have this code:
HTML:
<button onclick="test()">test</button><br>
javascript:
function test(){
  var text="Old text";  
  $.post('test.php',function(data){
      text=data;
    });
  alert(text);
}
PHP:
<?php
   echo "New text";
?>
but in the alert box I get "Old text". How do I fix this?
 
     
    