Javascript 可选表行无法通过jQuery AJAX将id值发送到PHP

Javascript 可选表行无法通过jQuery AJAX将id值发送到PHP,javascript,php,jquery,sql,Javascript,Php,Jquery,Sql,朋友们好,这是我的第一个问题。我是jquery+ajax的新手。我想选择我的表格行,并可以删除任何行时,选择它+点击删除按钮。现在我无法遍历DOM并将任何行的id发送到PHP文件 现在我可以: 可选择的表格行 显示在警报框中选择的id 选择并单击删除按钮时删除任意行 但我不能: 将所选文件上任何行的id发送到php文件(显示消息“undefined”) 将它们删除到数据库中 问题 -为什么警报框显示2,3,4,。。。当我选择行并单击删除按钮2,3,4,。。时代???我想展示一次 我该怎么办 对不

朋友们好,这是我的第一个问题。我是jquery+ajax的新手。我想选择我的表格行,并可以删除任何行时,选择它+点击删除按钮。现在我无法遍历DOM并将任何行的id发送到PHP文件

现在我可以:

  • 可选择的表格行
  • 显示在警报框中选择的id
  • 选择并单击删除按钮时删除任意行
  • 但我不能:

  • 将所选文件上任何行的id发送到php文件(显示消息“undefined”)
  • 将它们删除到数据库中
  • 问题 -为什么警报框显示2,3,4,。。。当我选择行并单击删除按钮2,3,4,。。时代???我想展示一次

    我该怎么办

    对不起,我的英语不好

    请帮帮我…非常感谢


    jQuery代码:

    $('#table2').selectable({
        filter:'tbody tr',
        stop: function(event, ui){
        $('#delete2').click(function(){
            var choose_data2 = $('#table2').find("tr.ui-selected").attr("id"); //--var for test--
            $('#table2').find("tr.ui-selected").remove('tr');
            $.ajax({
                url: 'http://localhost/dmht/tabs2_delete.php',
                type:'post',
                data:'choose_data2='+$('#table2').find("tr.ui-selected").attr("id"),
                cache: false,
                success :function(data){
                      alert(data);//---****---
                }
            });
        });
    });
    
    <?
    include ("connect.php");
    $q="DELETE FROM tabs2 WHERE HN = '".$_POST["choose_data2"]."'";
    mysql_query($q);
    echo $_POST["choose_data2"];
    mysql_close($link);
    ?> 
    
    <table id="table2">
     <tr>
        <th>1</th>
        <th>2</th>
        <th>3</th>
        <th>4</th>
    </tr>
    
    <tbody>
       <tr id="20/7/2014">
          <td>A</td>
          <td>B</td>
          <td>c</td>
          <td>D</td>
       </tr>
    </tbody>
    </table>
    <input type="button" name="delete2" id="delete2" value="Delete"/>
    
    ****-如果代码:“警报(数据);”-->当我单击删除按钮时,它将显示消息“未定义”

    • 如果代码为:“警报(选择_data2)”,则会显示“20/1/2013”,这是我需要返回的数据
    PHP代码(tabs2\u delete.PHP):

    $('#table2').selectable({
        filter:'tbody tr',
        stop: function(event, ui){
        $('#delete2').click(function(){
            var choose_data2 = $('#table2').find("tr.ui-selected").attr("id"); //--var for test--
            $('#table2').find("tr.ui-selected").remove('tr');
            $.ajax({
                url: 'http://localhost/dmht/tabs2_delete.php',
                type:'post',
                data:'choose_data2='+$('#table2').find("tr.ui-selected").attr("id"),
                cache: false,
                success :function(data){
                      alert(data);//---****---
                }
            });
        });
    });
    
    <?
    include ("connect.php");
    $q="DELETE FROM tabs2 WHERE HN = '".$_POST["choose_data2"]."'";
    mysql_query($q);
    echo $_POST["choose_data2"];
    mysql_close($link);
    ?> 
    
    <table id="table2">
     <tr>
        <th>1</th>
        <th>2</th>
        <th>3</th>
        <th>4</th>
    </tr>
    
    <tbody>
       <tr id="20/7/2014">
          <td>A</td>
          <td>B</td>
          <td>c</td>
          <td>D</td>
       </tr>
    </tbody>
    </table>
    <input type="button" name="delete2" id="delete2" value="Delete"/>
    

    哦,我已经试过了

    这是我更改的几个代码:

    var choose_data2 = $('#table2').find(".ui-selected td:first-child").text();  //<---- This changed code ----
    $('#table2').find("tr.ui-selected").remove('tr');
    
    $.ajax({
        url: 'http://localhost/dmht/tabs2_delete.php',
        type:'post',
        data:'choose_data2='+choose_data2, //<------ This changed code -----
        cache: false,
        success :function(data){
            alert(data);
        }
    });
    
    var choose_data2=$('#table2').find(“.ui selected td:first child”).text()//