[英]return value from .done to $this @ jquery ajax
control_td.each(function(){
$.ajax({
url: 'control.php?udid='+$(this).attr('udid'),
cache: false,
async: true
}).done(function(data) {
$(this).html(data);
});
});
but $this
doesn't work in .done
sub function. 但是$this
在.done
子函数中不起作用。 what am I doing wrong here? 我在这里做错了什么?
Its because this
doesn't refer to the element item in the callback. this
是因为它不引用回调中的元素项。
Try closing around a new value. 尝试以新值附近结算。
control_td.each(function(){
var $self = $(this); // magic here!
$.ajax({
url: 'control.php?udid='+$(this).attr('udid'),
cache: false,
async: true
}).done(function(data) {
$self.html(data);
});
});
Try this: 尝试这个:
control_td.each(function () {
var $this = $(this);
$.ajax({
url: 'control.php?udid=' + $this.attr('udid'),
cache: false,
async: true
}).done(function (data) {
$this.html(data);
});
});
You could also set the context
option of the $.ajax
, check this option . 您还可以设置$.ajax
的context
选项, 选中此选项 。
control_td.each(function(){
$.ajax({
url: 'control.php?udid='+$(this).attr('udid'),
cache: false,
async: true,
context: this
}).done(function(data) {
$(this).html(data);
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.