我有这个代码
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);
});
});
我从ajax得到的响应是这样的
Qualità 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 菜鸟
最佳答案
jQuery 的 post()
方法将 success 函数作为参数,就像您所做的那样。只需在其中包含您的插件初始化语句即可:
jQuery.post(ajaxurl, data_id, function(response) {
jQuery('#yasr_rateit_multi_rating').html(response);
jQuery('#myElement').rateIt();
});
关于javascript - ajax调用后重新加载jquery插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22715046/