What you have looks quite good for your first steps with AJAX. But you really need a webserver. To get your example work, do the following:
- Install a webserver on your machine. I suggest you use XAMPP for your first steps. Get it from here: http://www.apachefriends.org/en/xampp.html You should not have to configure something by yourself, just install it and you should end up with a webserver which runs "out-of-the-box".
- Place all your files in the
htdocs
folder. In my example I named the HTML fileajax.html
. - Ensure that your webserver is running. Open a browser and navigate to
localhost
. You should see a page with a big XAMPP on it. - Navigate to
localhost/ajax.html
. I tested your code and it worked.
Maybe this W3CSchools AJAX tutorial can provide you with more information about AJAX.