title: Passing data to PHP from Ajax
body: <p>I have the following code in ajax. I am passing two parameters, <code>$job_id</code> and <code>q</code> to a page called interview.php but. However, that page gives me a warning that <code>$job_id</code> is undefined. I am not sure how to POST or GET more then one variable using AJAX.</p>
  
  <p>My ajax file is:</p>
  
  <pre><code>&lt;script&gt;
  function showSuccess ($getid,str) {
    var job_id= $getid;
  var resp;
   if (window.XMLHttpRequest) {
      resp = new XMLHttpRequest();
      xmlhttp = new XMLHttpRequest();
  } else if (window.ActiveXObject) { 
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  }
  var data = "job_id="+job_id
       xmlhttp.open("POST", 
        "interview.php?q="+str); 
       xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");                  
       xmlhttp.send(data);
     xmlhttp.onreadystatechange =
    function display_data() {
     if (xmlhttp.readyState == 4) {
        if (xmlhttp.status == 200) {
          document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
  
  }
       } else {
          alert('Request not successful.');
        }
       }
    }
  
  
  &lt;/script&gt;
  </code></pre>
  
  <p>interview.php:</p>
  
  <pre><code>&lt;?php 
  $q = intval($_POST['q']);
  ?&gt;
  &lt;?php 
  
  $getid = $_POST['job_id'];?&gt;
  
  &lt;?php
  include('includes/conn.php');
  
  $row="SELECT  idNo,id,name,jobTitle,SUM(points) AS total FROM shortlist WHERE job='$getid' GROUP BY id ORDER BY total DESC LIMIT $q";
  $query=mysqli_query($conn,$row) or die(mysqli_error($conn));
  
  while($row=mysqli_fetch_array($query))
  {
    echo $row['name'];
  }
  
  mysqli_close($conn);
  ?&gt;
  </code></pre>