Ajax (this) not working

后端 未结 2 936
清歌不尽
清歌不尽 2021-01-11 19:35

When attempting to access the \'.box\' class of the $container, using (this) inside of the ajax call doesn\'t work.

$container.on(
        \"click\",
               


        
2条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-11 20:07

    You're close. 'this' in the context you are using it, refers to the ajax request rather than the thing that issued the event. To fix this, store a copy of this before making the ajax request:

                       }else{
                            var me = this;
                            $.ajax({
                                ...
                                success: function(data){
                                    description = data[0];
                                    $(me).css('width', '70%');
    

提交回复
热议问题