如何获得点击按钮的ajax响应?
HTML部分:
<button type="button" class="btn btn-success ccomment" rel="popover" data-original-title="Comment" value="12">click</button>
<button type="button" class="btn btn-success ccomment" rel="popover" data-original-title="Comment" value="460">click</button>
和 jquery脚本:
<script type='text/javascript' language='javascript'>
$('.ccomment').click(function(){
var ccomment_val = $(this).val();
$.ajax({
url: '/getcomment/'+ccomment_val,
type:'POST',
dataType: 'json',
success: function(output){
$('.ccomment').popover({
content: output,
html: true,
placement: 'right',
trigger: 'click'
});
}
});
});
</script>
我只想用有特定的按钮绑定有效的ajax响应。现在,输出与首先点击的按钮有关。
谢谢
答案 0 :(得分:0)
不是100%肯定你想要达到的目标,因为你的解释不是很好。但我已经发现了我认为脚本中的一个潜在问题,假设它做了我认为它做的事情。所以这是解决方案(我希望)。
在var ccoment_val....
行下面添加:
var self = $(this);
这将添加对单击按钮的引用,然后您可以在ajax响应中使用该按钮。因此,一旦添加了该行,请将ajax成功函数中的$('.ccomment').popover(
更改为:self.popover(
这应该解决我认为你想说的问题,如果没有,我道歉。
答案 1 :(得分:0)
$('button[value="'+ccomment_val+'"]').popover({
content: output,
html: true,
placement: 'right',
trigger: 'click'
});
您可以像这样更改弹出窗口绑定。希望它能起作用