title: xmlhttp.send() returns 404 Not Found (Ajax)
body: <p>I am using a sample of 2 files to practice ajax. I copied the code from <a href="http://www.w3schools.com/php/php_ajax_livesearch.asp" rel="nofollow">This Site</a> but when I try to run it it gives the following error <code>404 Not Found</code> in Javascript Console. Here is my html and php code :-</p>
  
  <p>HTML file</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;script type="text/javascript"&gt;
   function showResult(str){
   if (str.length==0)
      {
       document.getElementById("livesearch").innerHTML="";
       document.getElementById("livesearch").style.border="0px";
       return;
      }
   if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
      }
  
      xmlhttp.onreadystatechange=function()
       {
         if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200)
            {
              document.getElementById("livesearch").innerHTML=xmlhttp.responseText;
              document.getElementById("livesearch").style.border="1px solid #A5ACB2";
            }
       }
    xmlhttp.open("GET","livesearch.php?q="+str,true);
    xmlhttp.send();
    }
   &lt;/script&gt;
   &lt;/head&gt;
   &lt;body&gt;
   &lt;form&gt;
      &lt;input type="text" size="30" onkeyup="showResult(this.value)" /&gt;
      &lt;div id="livesearch"&gt;&lt;/div&gt;
   &lt;/form&gt;
  
   &lt;/body&gt;
   &lt;/html&gt; 
  </code></pre>
  
  <p>PHP File</p>
  
  <pre><code>&lt;?php
  $xmlDoc=new DOMDocument();
  $xmlDoc-&gt;load("http://localhost/php/ajax/links.xml");
  
  $x=$xmlDoc-&gt;getElementsByTagName('link');
  //get the q parameter from URL
  $q=$_GET["q"];
  
  //lookup all links from the xml file if length of q&gt;0
  if (strlen($q)&gt;0)
  {
    $hint="";
    for($i=0; $i&lt;($x-&gt;length); $i++)
      {
    $y=$x-&gt;item($i)-&gt;getElementsByTagName('title');
    $z=$x-&gt;item($i)-&gt;getElementsByTagName('url');
    if ($y-&gt;item(0)-&gt;nodeType==1)
    {
    //find a link matching the search text
    if (stristr($y-&gt;item(0)-&gt;childNodes-&gt;item(0)-&gt;nodeValue,$q))
    {
    if ($hint=="")
      {
      $hint="&lt;a href='" .
      $z-&gt;item(0)-&gt;childNodes-&gt;item(0)-&gt;nodeValue .
      "' target='_blank'&gt;" .
      $y-&gt;item(0)-&gt;childNodes-&gt;item(0)-&gt;nodeValue . "&lt;/a&gt;";
      }
    else
       {
       $hint=$hint . "&lt;br /&gt;&lt;a href='" .
       $z-&gt;item(0)-&gt;childNodes-&gt;item(0)-&gt;nodeValue .
       "' target='_blank'&gt;" .
       $y-&gt;item(0)-&gt;childNodes-&gt;item(0)-&gt;nodeValue . "&lt;/a&gt;";
       }
      }
     }
    }
   }
   if ($hint==""){
   $response="no suggestion";
   }
   else{
    $response=$hint;
    }
  
   //output the response
   echo $response;
   ?&gt; 
  </code></pre>