title: Replacing content using AJAX when clicking a link
body: <p>I want to use AJAX to replace the contents of a div. Although the application is fairly complex, I have tried to dumb it down in isolation so that I can get the basic concept working first.</p>
  
  <p>For now, I just want to replace a div as per the PHP file...</p>
  
  <pre><code>&lt;?php 
  $id = $_GET['id'];
  if ($id = 1)
      {
          $text = 'This is some text';
      }
  elseif ($id = 2) {
      {
          $text = 'This is a lot more text than the first text!';
      }
  elseif ($id = 3) {
      {
          $text = 'This is a lot more text than the first text, and a load more than the third as well!!';
      }
  echo $text; 
  ?&gt;
  </code></pre>
  
  <p>Fairly simple stuff really. So here's my HTML file...</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;script&gt;
  function loadXMLDoc()
  {
  var xmlhttp;
  if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
    }
  else
    {// code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  xmlhttp.onreadystatechange=function()
    {
    if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200)
      {
      document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
      }
    }
  
  
  xmlhttp.open("GET","ajax.php",true);
  xmlhttp.send();
  }
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;div id="myDiv"&gt;I want this content replacing&lt;/div&gt;
  &lt;a href="#" onclick="loadXMLDoc()"&gt;ID: 1&lt;/a&gt;&lt;br&gt;
  &lt;a href="#" onclick="loadXMLDoc()"&gt;ID: 2&lt;/a&gt;&lt;br&gt;
  &lt;a href="#" onclick="loadXMLDoc()"&gt;ID: 3&lt;/a&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I realise what is there will never work as I've modified some stuff I found online, but basically I'm looking to pass a variable such as the ID in the link to the AJAX script to replace the contents of the div.</p>
  
  <p>How do I get this working? Is there a better alternative to using <code>&lt;a&gt;</code> tags?</p>