title: How to delete record using ajax?
body: <p>I am trying to delete record from database using AJAX. The confirmation window does not appear so that the record can be deleted. here is the code..</p>
  
  <pre><code>&lt;?php
  $q = $_GET['q'];
  $p = $_GET['p'];
  $sql="SELECT * FROM course_details WHERE sem='" . $q . "' AND branch='" . $p . "' ORDER BY course_codes ASC";
  $result = mysql_query($sql);        
  while($row = mysql_fetch_assoc($result)){
    echo '&lt;tr class="record"&gt;';
    echo "&lt;td&gt;" . $row['course_codes'] . "&lt;/td&gt;";
    echo "&lt;td&gt;" . $row['course_names'] . "&lt;/td&gt;";
    echo "&lt;td&gt;" . $row['course_instructors'] . "&lt;/td&gt;";
    echo "&lt;td&gt;" . $row['course_credits'] . "&lt;/td&gt;";
    echo '&lt;td&gt;&lt;div align="center"&gt;&lt;a href="#" id="' . $row['course_id'] . '" class="delbutton" title="Click To Delete"&gt;delete&lt;/a&gt;&lt;/div&gt;&lt;/td&gt;';
    echo '&lt;/tr&gt;';
  }
  echo "&lt;/table&gt;";
  mysql_close($bd);
  ?&gt;
  </code></pre>
  
  <p>Here $p and $q are send by an AJAX script from another page. It is working fine. The records are displayed as expected. Deletion works using AJAX if i do not use AJAX to display records.The script I am using to delete is:</p>
  
  <pre><code>&lt;script src="jquery.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
  $(function() {
  $(".delbutton").click(function(){
  var element = $(this);
  var del_id = element.attr("id");
  var info = 'id=' + del_id;
  if(confirm("Are you sure you want to delete this Record?")){
      $.ajax({
          type: "GET",
          url: "deleteCourse.php",
          data: info,
          success: function(){   
      }
  });
      $(this).parents(".record").animate({ backgroundColor: "#fbc7c7" }, "fast")
      .animate({ opacity: "hide" }, "slow");
  }
  return false;
  });
  });
  &lt;/script&gt;
  </code></pre>
  
  <p>deleteCourse.php</p>
  
  <pre><code>if($_GET['id']){
      $id=$_GET['id'];
      $id = mysql_escape_string($id);
  }
  $del = "DELETE from course_details where course_id = '$id'";
  
  $result = mysql_query($del);
  </code></pre>