[英].html not working with live() Jquery
我正在尝试使用live
方法,并且该方法最初可以按预期运行,但是ajax的“成功”回调在该函数的后续运行中无法正常运行。
$(function () {
$('.vote').live('click', function () {
url = '".base_url()."post/vote';
post_id = $(this).attr('id');
$.ajax({
url: url,
type: 'POST',
data: 'post_id=' + post_id,
success: function (msg) {
post = $('.num_vote' + post_id);
vote = $('.votes' + post_id);
$(vote).html(msg); // working only the first time
}
});
return false;
});
});
根据所使用的jQuery版本,您可能需要使用.on函数,因为.live()在1.7中已弃用,在1.9中已删除。
$(function(){
$('.vote').on( 'click', function() {
url = '".base_url()."post/vote';
post_id = $(this).attr('id');
$.ajax({
url: url,
type: 'POST',
data: 'post_id=' + post_id,
success: function(msg) {
post = $('.num_vote' + post_id);
vote = $('.votes' + post_id);
$(vote).html(msg); // working only the first time
}
});
return false;
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.