title: Trying to send a string to php file using ajax
body: <p>So i am trying to send a string into a php file using ajax but the http.send is not working, maybe something is wrong with the code? (i am just a beginner)</p>
  
  <pre><code> mainlink= 'a link';
   id= 'an id';
   $(document).click(function(){
     var http = new XMLHttpRequest();
     var link = mainlink+id;
     http.open("POST", 'test.php', true);
     http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
     http.onload = function(){
       if(this.status == 200) {
         console.log (link);
       }
     }
     http.send("link="+link);
   });
  </code></pre>
  
  <p>test.php:</p>
  
  <pre><code>&lt;?php 
  if (isset($_POST['link'])){
  echo $_POST['link'];
  } else{echo "error";}
  ?&gt;
  </code></pre>
  
  <p>i tried both GET and POST.</p>