Home  >  Article  >  Web Front-end  >  Problem with calling $(this) in jquery ajax callback function

Problem with calling $(this) in jquery ajax callback function

伊谢尔伦
伊谢尔伦Original
2016-11-22 11:34:501031browse

A problem occurred when using jquery's ajax callback function, that is, $(this) cannot be used in the callback function. I have been working on this problem for a long time, but I can't solve it. Later, I saved $(this) into a variable before calling the function, and then used it in the callback function. There was no problem. I will make a note here.

$(document).ready(function(){
    $(“.del”).click(function () {
        obj=$(this).parent();//回调函数前先写入变量;
        delid=$(this).attr(‘delid’);
        $.get(‘drag.php’,{‘op’ : ‘del’,'id’ : delid},function(data){
            if(data==1){
                alert(‘删除成功’);
                obj.remove();//直接写$(this).parent()不会起作用。
            }else{
                alert(‘删除失败’);
            }
        });
    });
});


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn