Basic PHP and AJAX

If you are going to use AJAX I would recommend using jQuery as well. This greatly simplifies the process, is tested cross-browser and has many easy to use wrapper functions.

Its really as easy as creating a PHP page called hello.php

<?php
  echo "Hello World";
?>

Then in your main page you will need to grab the jQuery library and hook it up to the document ready event.

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script type="text/javascript">
     $(function(){
       $.get("hello.php", function(data){
           alert(data);
       });
    });
</script>

This in essence is the simplest AJAX hello world tutorial I know 🙂

Leave a Comment

tech