dongluolie3487 2015-11-05 10:29
浏览 76
已采纳

Jquery fadeOut()在Ajax中不起作用

I have a .php file that makes a table filled with items found in a database. Here is the while-loop that fills the table:

while($request = $list->fetch(PDO::FETCH_ASSOC)) {
  if(!in_array(array($request['artist'], $request['title']), $arrayList)) {
    echo "<tr id='remove-" . $count . "'>";
    echo "<td class='". $count . "'>" . $count . "</td>";
    echo "<td class='artist'>" . $request['artist'] . "</td>";
    echo "<td class='title'>" . $request['title'] . "</td>";
    echo "<td>" . ShowTime($request['time_created']) . "</td>";
    echo "<td><button type='button' class='btn btn-success played'><span class='ion-play' aria-hidden='true'></span></button></td>";
    echo "<td><button type='button' class='btn btn-danger deletesong'><span class='ion-trash-a' aria-hidden='true'></span></button></td>";
    echo "</tr>";

    $count++;

    $arrayList[$request['id']] = [$request['artist'], $request['title']];
  }
}

When a person clicks on one of the '.played' buttons, an ajax 'POST' request is sent to set a parameter in the database to 1. This is handled by a different script, which is working correctly, because the parameter is set when I click on the button. This is the jQuery file that handles the click on the button:

$('button.played').click(function() {
  var number = $(this).closest( "tr" ).children( ".count" ).html();
  var artist = $(this).closest( "tr" ).children( ".artist" ).html();
  var title = $(this).closest( "tr" ).children( ".title" ).html(); 
  var data = "artist=" + artist + "&title=" + title;
  var trid = "remove-" + number;
  var $parent_tr = $('#'+trid);

  $.ajax({
    type: "POST",
    url: "/assets/scripts/php/played_request.php",
    data: data,
    cache: false,

    success: function() {
      $parent_tr.fadeOut( 1000, function() {
        $(this).remove();
      });
    }
  });
});

The problem is that even though the AJAX is handled successfully (The success block is called), the fadeOut function is not responding, because nothing is fading out. I can't find the problem and this function works in the console.

jQuery(parent_tr).fadeOut( 1000, function() {
  $(this).remove();
});

Can someone please explain to me what I'm doing wrong?

  • 写回答

2条回答 默认 最新

  • dtamho6404 2015-11-05 10:43
    关注

    Change your code like:

    var $parent_tr = $(this).closest( "tr" );
    

    As I don't see any element with class like count in your HTML.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起