title: Ajax Php Delete a file from server
body: <p>I can not seem to figure out what I'm missing could you all give me some help?</p>
  
  <pre class="lang-js prettyprint-override"><code>function deleteFile(file){
  
  var file = encodeURIComponent(file);
  
  
  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("media").innerHTML=xmlhttp.responseText;
  }
  }
  xmlhttp.open("GET", "http://www.bennettauto.biz/file-tree-hr/delete.php?file=\""+file, true);
  xmlhttp.send();
  alert(clicked);
  }
  </code></pre>
  
  <p>HTML:</p>
  
  <pre><code> &lt;div id='TrashFile'&gt;&lt;a href="javascript:void(0)"onClick='deleteFile(&lt;? echo $deletefile; ?&gt;);'&gt;&lt;img src='http://www.bennettauto.biz/images/tool_trash.gif'&gt;&lt;/a&gt;&lt;/div&gt;
  </code></pre>
  
  <p>delete.php:</p>
  
  <pre><code>&lt;?php
      // I save the file sources from the URL what was sent by AJAX to these variables.
      $file = $_GET['file'];
  
  
      function deleteFiles($id){
          // If is a file then delete the file.
          if(is_file($id)){
              return unlink($id);
          // Else show error.
          } else {
              echo $id . " is not a file, or there is a problem with it.&lt;br /&gt;" ; 
          }
      }
  
      if(isset($file)){
          deleteFiles($file);
      }
  
  
   ?&gt;
  </code></pre>
  
  <p>The onClick function does not seem to be calling delete.php, there is something I'm missing but I can't see what.</p>