Javascript 为什么我的ajax post发布在正确的表中,但它发布所有id';什么在第页?

Javascript 为什么我的ajax post发布在正确的表中,但它发布所有id';什么在第页?,javascript,php,jquery,mysql,ajax,Javascript,Php,Jquery,Mysql,Ajax,好的,这有点奇怪,所以我会尽量简单地解释。php从挂起的数据库中提取所有内容,然后放入foreach循环。示例:我在挂起的表中有两个故事,我的管理页面显示了这两个故事,每个故事都有不同的Id。每当我单击向school1表添加一个时,它都会将两个故事放在school1中,而不仅仅是我单击的1个故事 admin.php: foreach ($list as $rs) { ?> <?php echo '<p>id:'.$rs['id']. '</p

好的,这有点奇怪,所以我会尽量简单地解释。php从挂起的数据库中提取所有内容,然后放入foreach循环。示例:我在挂起的表中有两个故事,我的管理页面显示了这两个故事,每个故事都有不同的Id。每当我单击向school1表添加一个时,它都会将两个故事放在school1中,而不仅仅是我单击的1个故事

admin.php:

foreach ($list as $rs) {
    ?>
        <?php echo '<p>id:'.$rs['id']. '</p><br>';?>
        <!--school 1 table add--><?php echo 'school1<a href="#" class="add_button" id="del-'.$rs["id"]. '"><img src="images/add.png"></a>&nbsp;&nbsp;';?>
        <!--school 2 table add--><?php echo 'school2<a href="#" class="add_button_school2" id="del-'.$rs["id"]. '"><img src="images/add.png"></a>&nbsp;&nbsp;';?>      
    <?php
  }
注意:我确实有2个php文件,但这将很快改变,因为我们正在清理代码。但是我仍然会遇到同样的问题,因为看起来php没有什么问题,而是ajax调用发送数据

//##### Send add Ajax request to responseadd.php ######### - School 1 post
$("body").on("click", " .add_button", function(e) {
     e.preventDefault();
     var clickedID = this.id.split('-'); //Split ID string (Split works as PHP explode)
     var DbNumberID = clickedID[1]; //and get number from array
     var myData = 'recordToDelete='+ DbNumberID; //build a post data structure

    $('#item_'+DbNumberID).addClass( "sel" ); //change background of this element by adding class
    $(this).hide(); //hide currently clicked delete button

        jQuery.ajax({
        type: "POST", // HTTP method POST or GET
        url: "responseadd.php", //Where to make Ajax calls
        dataType:"text", // Data type, HTML, json etc.
        data:myData, //Form variables
        success:function(response){
            //on success, hide  element user wants to delete.
            $('#item_'+DbNumberID).fadeOut();
        },
        error:function (xhr, ajaxOptions, thrownError){
            //On error, we alert user
            alert(thrownError);
        }
        });
});

//##### Send add Ajax request to responseaddschool2.php ######### - School 2 post
$("body").on("click", " .add_button_school2", function(e) {
     e.preventDefault();
     var clickedID = this.id.split('-'); //Split ID string (Split works as PHP explode)
     var DbNumberID = clickedID[1]; //and get number from array
     var myData = 'recordToDelete='+ DbNumberID; //build a post data structure

    $('#item_'+DbNumberID).addClass( "sel" ); //change background of this element by adding class
    $(this).hide(); //hide currently clicked delete button

        jQuery.ajax({
        type: "POST", // HTTP method POST or GET
        url: "responseaddschool2.php", //Where to make Ajax calls
        dataType:"text", // Data type, HTML, json etc.
        data:myData, //Form variables
        success:function(response){
            //on success, hide  element user wants to delete.
            $('#item_'+DbNumberID).fadeOut();
        },
        error:function (xhr, ajaxOptions, thrownError){
            //On error, we alert user
            alert(thrownError);
        }
        });
});