Uncaught TypeError: Cannot call method 'toLowerCase' of undefined

后端 未结 4 1999
挽巷
挽巷 2021-02-06 23:49

I ran into a very vague error while doing some simple jQuery DOM manipulation.

The line that triggered the error is the following:

$(this).closest(\'tr\')

4条回答
  •  北荒
    北荒 (楼主)
    2021-02-07 00:31

    I don't know what you expect the value of this to be in your "success" handler, but I bet it's not what you think. Save this outside the "$.ajax()" call:

    var clicked = this;
    $.ajax(
      // ...
      success: function(res) {
        if (res) {
          $(clicked).closest('tr').remove();
        }
        else {
          // ...
        }
      }
    );
    

提交回复
热议问题