sending AJAX post id for MySQL delete
Hi guys,
I am trying to do something simple in PHP but using jQuery AJAX. I don't know about Javascript, so take it easy on me!
I have made a deleteajax.php
- require_once('../Connections/conn.php'); //database connection
- if($_POST['id'])
- {
- $id=$_POST['id'];
- $id = mysql_escape_String($id);
- mysql_select_db($database_XXXX, $conn);
- $sql = "DELETE FROM students WHERE student_id ='$id'";
- mysql_query( $sql);
- }
and using this script on the main page
- <script type="text/javascript">
- $(function() {
- $(".delete_button").click(function() {
- var id = $(this).attr("id");
- document.write(id);
- var dataString = 'id='+ id ;
- var parent = $(this).parent();
- $.ajax({
- type: "POST",
- url: "deleteajax.php",
- data: dataString,
- cache: false,
- success: function()
- {
- if(id % 2)
- {
- parent.fadeOut('slow', function() {$(this).remove();});
- }
- else
- {
- parent.slideUp('slow', function() {$(this).remove();});
- }
- }
- });
- return false;
- });
- });
- </script>
and this link in the body to send the delete request
- <a href="#" id="510" class="delete_button">X</a>
What is wrong? It is not refreshing the page (good) but I can't track what is being posted.. tried HTTP live headers, nothing happens.
Any ideas?