title: How do we pass data in ajax?
body: <p>I am new to Ajax and I am confused as to how we pass data in Ajax. I have an index.php file which displays some data, it has a link to delete the record, now the problem is, I am not able to figure out how to transfer the id value from index.php of the selected record to ajax file. Also, how should I go about once I have fetched the value in delete.php page where lies the code to delete records.
  I have coded as below.</p>
  
  <h3>index.php</h3>
  
  <pre><code>&lt;div id="delMsg"&gt;&lt;/div&gt;
  &lt;?php
  $con=mysqli_connect("localhost","root","","ajaxtest");
  $data=mysqli_query($con,"select * from member");
  $col=mysqli_num_fields($data);
  echo "&lt;table&gt;";
  while($row=mysqli_fetch_array($data))
  {
      echo "&lt;tr&gt;";
      for($i=0;$i&lt;$col;$i++)
      {
          echo "&lt;td&gt;".$row[$i]."&lt;/td&gt;";
  
      }
      echo "&lt;td&gt;&lt;a class='del' href='delete.php' data-ID=$row[0]&gt;Delete&lt;/a&gt;&lt;/td&gt;";
      echo"&lt;/tr&gt;";
  }
  echo "&lt;/table&gt;";
  ?&gt;
  </code></pre>
  
  <p><h3>ajax-file.js</h3></p>
  
  <pre><code>$(document).ready(function(){
      $(".del").click(function(event){
      event.preventDefault();
      $.ajax({
          url:"delete.php",
          method:"get",
          data:{id:'ID'},
          dataType:"html",
          success:function(str){
              $('#delMsg').html(str);
              }
  
          })
  
      })  
  })
  </code></pre>
  
  <h3>delete.php</h3>
  
  <pre><code>&lt;?php
  $id=$_GET['id'];
  
  $con=mysqli_connect("localhost","root","","ajaxtest");
  $data=mysqli_query($con,"delete from member where id='$id'");
  if($data)
  {
      echo "success"; 
  }
  else
  {
      echo "error";   
  }
  
  ?&gt;
  </code></pre>