Javascript 使用setInterval更新按钮上的文本
我正在尝试使用idJavascript 使用setInterval更新按钮上的文本,javascript,jquery,ajax,laravel,Javascript,Jquery,Ajax,Laravel,我正在尝试使用idfixed button定期更新我按钮上的文本: <script type="text/javascript"> $(function() { $('#fixed-button').setInterval(function() { $.getJSON("{{ url('schedulizer/cart') }}", function(data) { $(this).text(da
fixed button
定期更新我按钮上的文本:
<script type="text/javascript">
$(function()
{
$('#fixed-button').setInterval(function() {
$.getJSON("{{ url('schedulizer/cart') }}", function(data) {
$(this).text(data.quantity);
});
}, 5000);
});
</script>
问题很明显,此
属性没有.setInterval
函数。所以问题是-我如何在固定的时间段内使用AJAX设置这个按钮元素上的文本
setInterval
不是jQuery函数,而是javascript函数
$(函数()
{
var$this=$(“#固定按钮”);
setInterval(函数(){
$.getJSON({url('schedulizer/cart')}}),函数(数据){
$this.text(数据.数量);
});
}, 5000);
});
DOC:谢谢,我最终没有使用间隔,因为我意识到我可以在按下按钮时触发文本更改(我正在为我的站点开发购物车模块,因此添加到购物车将触发文本更改而不是间隔)。“不过,这很管用。”绿卷心菜:很乐意帮忙:)
Uncaught TypeError: $(...).setInterval is not a function
<script type="text/javascript">
$(function()
{
var $this=$('#fixed-button');
window.setInterval(function() {
$.getJSON("{{ url('schedulizer/cart') }}", function(data) {
$this.text(data.quantity);
});
}, 5000);
});
</script>