繁体   English   中英

AJAX在成功时更改了Element的HTML

[英]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 &amp; 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'))是未定的

有什么建议么?

你的问题是, thissuccess的回调是不一样的this在上下文each回调。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM