title: Calling PHP Function from javascript in the same file using ajax
body: <p>So, I'm trying to call a php function from the same file where the javascript lies.</p>
  
  <p>I'm trying to call the php function every 10 sec to add new items to the "li"</p>
  
  <pre><code>&lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"&gt;
  
  function addElement () {
  var newLi = document.createElement("li");
  var text = document.createTextNode("Teststring in &lt;li&gt;");
  
  newLi.appendChild(text);
  var ulnew = document.getElementsByClassName('new-item');
  ulnew[0].appendChild(newLi)    
  }
  window.onload = function(){setInterval(function(){
      $.ajax( // I just copy pasted this part to
             {
                 url: 'test.php',
                 type: 'GET',
                 success: function(output) 
                 {
                        //alert(output);
                        document.write("It worked!"); 
                 }
              }
          );// here I really have no idea what is suppose to happen here
  },10000);}
  &lt;/script&gt;
  
  &lt;?php 
  
  function echoTest(){
     echo 'item';
  }
  
  ?&gt;
  </code></pre>
  
  <p>Again, What I'm trying to do is Execute a php function every 10 sec. How am I going to do this? 
  Please Help!</p>