MySQL循环只能删除第一个数据?

时间:2015-10-09 03:27:56

标签: javascript php jquery mysql

我有MySQL循环,当我点击第二个按钮获取他们的ID并做休息处理它不工作。为什么会这样?

$(document).ready(function() {
$("#deleteSchedule").click(function (e) {
    e.preventDefault();
    var url_tna = "<?php echo $_SESSION['url_address'];?>mods/agent_management/code/";
    var deleteSchedule =$("#deleteSchedule").val(); //build a post data structure

    var JsonData = {deleteSchedule: deleteSchedule};  

    jQuery.ajax({
        type: "POST", // Post Get method
        url: url_tna+"email_template_response.php", //Where form data is sent on submission
        dataType:"text", // Data type, HTML, json etc.
        data:JsonData, //Form variables
        success:function(response){
            window.location.reload(true); // reload before append
            $("#responds").append(response);
            document.getElementById("contentText").value = "";
        },
        error:function (xhr, ajaxOptions, thrownError){
            alert(thrownError);
        }
    });
});
});
</script>



<?php $i=1; while ($row = mysql_fetch_array($result)) { ?>

             <tr>

                <td><?php  echo $i; ?></td> 
                     <td><input type="textarea" id="TitleData" name="TitleData"  value="<?php echo $row['niceDate']; ?>" ></input></td> 
                     <td><button id="deleteSchedule" name="deleteSchedule" class="del_button" value="<?php echo $row['id'];?>"><a href="#" style="display:block" class="button insertcolumn" id="<?php echo $row['id'];?>">Delete</a></button></td>
                    <? $i++;}?>
                </tr>   
        </table>

only first button work

1 个答案:

答案 0 :(得分:1)

您需要在脚本中使用alignment而不是class

  

在你的Js中:

ID
  

在你的PHP中:

$(document).ready(function() {
$(".deleteSchedule").click(function (e) {
    e.preventDefault();
    var url_tna = "<?php echo $_SESSION['url_address'];?>mods/agent_management/code/";
    var deleteSchedule =$(this).val(); //build a post data structure

    var JsonData = {deleteSchedule: deleteSchedule};  

    jQuery.ajax({
        type: "POST", // Post Get method
        url: url_tna+"email_template_response.php", //Where form data is sent on submission
        dataType:"text", // Data type, HTML, json etc.
        data:JsonData, //Form variables
        success:function(response){
            window.location.reload(true); // reload before append
            $("#responds").append(response);
            document.getElementById("contentText").value = "";
        },
        error:function (xhr, ajaxOptions, thrownError){
            alert(thrownError);
        }
    });
});
});
</script>