[英]AJAX change HTML of Element on succes
我有一个AJAX调用,可以找到类videoReplace
任何元素
jQuery('.videoReplace').each(function(index) {
jQuery.ajax({
type: 'post',
url: 'http://optinsmart.com/videos.php',
cache: false,
data:{
'video': jQuery( this ).attr('video-source')
},
dataType: 'html',
success:function(data){
jQuery('#'+jQuery( this ).attr('id')).html(data);
},
error: function(errorThrown){
console.log(errorThrown);
}
});
});
这是我的HTML
<h2>Tanya & Matt Ice Cream</h2>
<div id="tanya" id-name="tanya" class="videoReplace" video-source="Opt-in Smart review by Tanya_Matt Ice cream"></div>
理论上这段代码应发布到我的视频页面,视频播放以html格式发回。 然后我想将html添加到我正在使用的div中。
它告诉我jQuery('#'+jQuery( this ).attr('id'))
是未定的
有什么建议么?
你的问题是, this
在success
的回调是不一样的this
在上下文each
回调。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.