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 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路
  • ¥15 经gamit解算的cors站数据再经globk网平差得到的坐标做形变分析
  • ¥15 GD32 SPI通信时我从机原样返回收到的数据怎么弄?
  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错
  • ¥20 @microsoft/fetch-event-source 流式响应问题
  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!