2014-03-28 58 views
1

我有这个代码刷新jQuery插件

jQuery('#select_set').on("change", function() { 
    var data_id = { 
     action: 'yasr_send_id_nameset', 
     set_id: jQuery(this).val() 
} 

    //Send value to the Server 
    jQuery.post(ajaxurl, data_id, function(response) { 
      jQuery('#yasr_rateit_multi_rating').html(response); 
    }); 
    }); 

,我从阿贾克斯得到的回应是这样的

Qualit&agrave; birra <div class="rateit" id="yasr_rateit_multi_0" data-rateit-value="" data-rateit-step="0.5" data-rateit-resetable="true" data-rateit-readonly="false"> 
        </div> <br /> 

我可以输出只是简单的文本,但我不能输出div:该div调用一个名为“rateit”的jquery插件。我认为我应该重新加载Ajax响应后的插件,但我不知道如何做到这一点。我是js中的总noob

+1

这怎么原名加载页面时?你只需要在成功处理函数中使用相同的代码来调用'jQuery.post()'(你已经为一个元素设置了新的HTML内容)。 –

回答

1

jQuery的post()方法将成功函数作为参数,就像您所做的一样。只要有你的插件初始化语句有:

jQuery.post(ajaxurl, data_id, function(response) { 
    jQuery('#yasr_rateit_multi_rating').html(response); 
    jQuery('#myElement').rateIt(); 
}); 

https://api.jquery.com/jQuery.post

+0

谢谢伊舍伍德,它的工作原理! – Dudo1985