-1

我有一个 php 页面,它在删除数据之前使用 jQuery 进行确认,事实上,当我点击删除它没有做任何事情时,链接没有做任何事情,我尝试了我的努力仍然没有任何反应,请帮助我

我的代码teacher.php

    <?php
    require_once('../auth.php');
?>
<html>
<head>
<title>Silay Institute</title>
<link rel="stylesheet" href="../css/main.css" type="text/css" media="screen" />
<!--sa poip up-->
<link href="src/facebox.css" media="screen" rel="stylesheet" type="text/css" />
   <script src="lib/jquery.js" type="text/javascript"></script>
  <script src="src/facebox.js" type="text/javascript"></script>
  <script type="text/javascript">
    jQuery(document).ready(function($) {
      $('a[rel*=facebox]').facebox({
        loadingImage : 'src/loading.gif',
        closeImage   : 'src/closelabel.png'
      })
    })
  </script>
    <link rel="stylesheet" href="febe/style.css" type="text/css" media="screen" charset="utf-8">
<script src="argiepolicarpio.js" type="text/javascript" charset="utf-8"></script>
<script src="js/application.js" type="text/javascript" charset="utf-8"></script>
<style>
#mainhhh {
    background: none repeat scroll 0 0 #FFFFFF;
    border: 8px solid #EEEEEE;
    border-radius: 5px 5px 5px 5px;
    box-shadow: 0 0 10px #4E707C;
    font: 11px "Trebuchet MS",Verdana,Arial,Helvetica,sans-serif;
    margin: 5em auto;
    position: relative;
    text-align: left;
    width: 1000px;
}
#mainhhh h1 {
    background: none repeat scroll 0 0 #0092C8;
    border-bottom: 1px solid #007DAB;
    color: #FFFFFF;
    font-size: 14px;
    margin: 0;
    padding: 5px 10px;
    text-shadow: 0 1px 0 #007DAB;
}
</style>    
</head>
<body>
<div id="mainhhh">
<h1>
<a id="addq" href="index.php" title="click to enter homepage" style="background-image:url('../images/out.png'); background-repeat:no-repeat; padding: 3px 12px 12px; margin-right: 10px;"></a>
<label for="filter">Filter</label> <input type="text" name="filter" value="" id="filter" />
    <a rel="facebox" href="addteacher.php" id="addq">Add Teacher</a>

</h1>

        <table cellpadding="1" cellspacing="1" id="resultTable">
            <thead>
                <tr>
                    <th  style="border-left: 1px solid #C1DAD7"> Name </th>
                    <th>ID Number</th>
                    <th>Work</th>
                    <th>Gender</th>
                    <th>Status</th>
                    <th>Birthday</th>
                    <th>Advisory</th>
                    <th> Action </th>
                </tr>
            </thead>
            <tbody>
            <?php
                include('../connect.php');
                $result = mysql_query("SELECT * FROM teacher");
                while($row = mysql_fetch_array($result))
                    {
                        echo '<tr class="record">';
                        echo '<td  style="border-left: 1px solid #C1DAD7">'.$row['fname'].' '.$row['mname'].' '.$row['lname'].'</td>';
                        echo '<td><div align="left">'.$row['idnumber'].'</div></td>';
                        echo '<td><div align="left">'.$row['work'].'</div></td>';
                        echo '<td><div align="left">'.$row['gender'].'</div></td>';
                        echo '<td><div align="left">'.$row['status'].'</div></td>';
                        echo '<td><div align="left">'.$row['bday'].'</div></td>';
                        echo '<td><div align="left">';
                        $sdsd=$row['idnumber'];
                        $results = mysql_query("SELECT * FROM `teacher` JOIN `advisory` ON `advisory`.`tid`=`teacher`.`idnumber`");
                            while($rows = mysql_fetch_array($results))
                                {
                                echo $rows['level'].' section '.$rows['section'];
                                }
                        echo '</div></td>';
                        echo '<td><div align="center"><a rel="facebox" href="editprofile.php?id='.$row['id'].'" title="Click To Edit">Edit Profile</a> | <a href="#" id="'.$row['id'].'" class="delbutton" title="Click To Delete">delete</a></div></td>';
                        echo '</tr>';
                    }
                ?> 
            </tbody>
        </table>
</div>  
<script src="js/jquery.js"></script>
  <script type="text/javascript">
$(function() {


$(".delbutton").click(function(){

//Save the link in a variable called element
var element = $(this);

//Find the id of the link that was clicked
var del_id = element.attr("id");

//Built a url to send
var info = {'id': del_id};

 if(confirm("Sure you want to delete this update? There is NO undo!"))
          {

 $.ajax({
   type: "GET",
   url: "deleteteacher.php",
   data: info,
   success: function(){

   }
 });
         $(this).parents(".record").animate({ backgroundColor: "#fbc7c7" }, "fast")
        .animate({ opacity: "hide" }, "slow");

 }

return false;

});

});
</script>
</body>
</html>

删除老师.php

<?php

// This is a sample code in case you wish to check the username from a mysql db table
include('../connect.php');
if($_GET['id'])
{
$id = intval($_GET['id']); 
 $sql = "delete from teacher where id='$id'";
 mysql_query( $sql);
}

?>
4

1 回答 1

0

As I remember, you should send a JSON object as data; its means you should make a dictionary, not just an assignment. When you write $_GET['id'] compiler searches for an element in the data dictionary with key "id" to returns its value; but since you don't send a dictionary structured data, it returns NULL and of course nothing will happen.

You should write something like this in your delete function:

var info = {'id': del_id};

于 2013-09-29T09:35:39.030 回答