Your code does work, But it never gets called.
The ajax call doesnt reload the page, So when the page was processed, there was no $_POST['name'] there.
The ajax version of the page will have that variable set, but the one your currently running in does not.
Your process is
GET PAGE => => show post name
AJAX Request => Post =>
It should be
GET PAGE =>
AJAX Request => post => show post name
As you can see, The Ajax request doesnt touch the post name in your version. You need to get the data from the ajax request and then do something with that. Not the original page version
Your post should return something javascript can parse, Either plain text or JSON