ajax回调函数中使用$(this)取不到对象的解决方法
$(".derek").each(function(){
$(this).click(function(){
varparams=$(this).parent().serialize();
varobj=$(this).parent().siblings("div#caskContent");
varform=$(this).parent();
$.ajax({
url:"editCaskContent",
type:"post",
data:params,
dataType:"json",
success:function(e){
obj.empty();
obj.html("<fontcolor=\"#00AA00\">追问:</font>");
obj.append(e.caskContent);
form.toggle();
alert("修改成功!");
},
error:function(e){
alert(e);
}
});
});
});
其中,大家可以看到,在发出ajax请求之前,我提前定义了两个变量,obj和form,分别用来存储两个jquery对象。如果在ajax的回调函数内使用$(this)的话,实践证明,是取不到任何对象的。具体原因,希望大神留言指教。。
热门推荐
10 祝孙辈生日祝福语简短
11 恋人跨年祝福语大全简短
12 考大学敬酒简短祝福语
13 开工投产大吉祝福语 简短
14 偶然结婚祝福语朋友简短
15 感谢学长学姐祝福语简短
16 戏精的祝福语简短
17 我要结婚祝福语简短
18 婚前女儿生日祝福语简短