简体   繁体   中英

Reload jquery plugin after ajax call

I've this code

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); 
     });
  });

The response that i got from ajax is something like this

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 /> 

I can output just the simple text but i can't output the div: that div call a jquery plugin called "rateit". I think that i should reload the plugin after ajax response but I've not idea how to do this. I'm a total noob in js

jQuery's post() method takes the success function as a parameter, as you've done. Just include your plugin init statement there:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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