Ajax callback function using $(this) can not get the object solution

Time:2021-5-13

The following jQuery code can achieve the expected effect.

Copy codeThe code is as follows:
$(“.derek”).each(function(){
$(this).click(function(){
var params = $(this).parent().serialize();
var obj=$(this).parent().siblings(“div#caskContent”);
var form=$(this).parent();
$.ajax({
url:”editCaskContent”,
type:”post”,
data:params,
dataType:”json”,
success:function(e){
obj.empty();
Obj. HTML (“< font color = \” ා00aa00 \ “> follow up: < / font >”);
obj.append(e.caskContent);
form.toggle();
Alert (“modified successfully!”);
},
error:function(e){
alert(e);
}
});
});
});

As you can see, before making Ajax requests, I defined two variables, obj and form, to store two jQuery objects. If you use $(this) in the callback function of Ajax, practice has proved that you can’t get any object. Specific reasons, I hope the God message..