简体   繁体   English

如何在我的网站上自动更新以太坊价格

[英]How can I automatically update ethereum price on my website

I want to display the last price of etherum on my website but unfortunately it doesn't update automatically without reloading the page.我想在我的网站上显示以太坊的最新价格,但不幸的是它不会在不重新加载页面的情况下自动更新。

<script>
  $.ajax({

    url : 'https://api.coinmarketcap.com/v1/ticker/ethereum/',
    type : 'GET',
    data : {
        'numberOfWords' : 10
    },
    dataType:'json',
    success : function(data) {
        eth_price = data[0].price_usd;
        document.getElementById('eth_price').innerHTML = eth_price;
    },
    error : function(request,error)
    {
        console.log('Error by getting the ETH price');
    }
  });
</script>

How can I fix this so the last price is always displayed without reloading the site every time?如何解决此问题,以便始终显示最后价格,而无需每次都重新加载网站?

I thought ajax is doing that by default?我认为 ajax 默认是这样做的?

The setInterval() method calls a function or evaluates an expression at specified intervals (in milliseconds). setInterval() 方法以指定的时间间隔(以毫秒为单位)调用函数或计算表达式。

setInterval(function(){ 
 $.ajax({

    url : 'https://api.coinmarketcap.com/v1/ticker/ethereum/',
    type : 'GET',
    data : {
        'numberOfWords' : 10
    },
    dataType:'json',
    success : function(data) {
        eth_price = data[0].price_usd;
        document.getElementById('eth_price').innerHTML = eth_price;
    },
    error : function(request,error)
    {
        console.log('Error by getting the ETH price');
    }
  })
}, 3000);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使网站按价格从大到小排序 - How can I make the website sort by price from greatest to smallest 每当我的网站出现错误时,我可以自动创建 jira 问题吗? - Can I automatically create a jira issue whenever there is an error on my website? 当我向下滚动我的网站页面时,如何让进度条更新? - How can I get progress bar to update as I scroll down my website page? 如何让我的 discord.js 机器人“正在观看 X 服务器”状态自动更新? - How can I get my discord.js bots “Watching X Servers” status, to automatically update? 如何自动更新我的JavaScript文件以导入新检测到的文件? - How can I automatically update my javascript file to import newly detected files? 我如何将价格添加到我的购物车中,例如切换? - how can i add price to my shop cart like toggle? 如何让我的网站检查访问者的 java 安装并提供更新或安装它? - How can I have my website check the visitor's java installation and offer to update or install it? 我如何在我的网站上有效地加载某人的 Steam 库存和他们每件商品的价格? - How do I efficiently load someone's steam inventory and price of their every item on my website? 如何让用户上传的图片在我的 PHP 网站上自动调整到特定的宽度和高度而不会破坏尺寸? - How can I make a picture a user uploaded to automatically adjust to a specific width and height on my PHP website without spoiling the dimentions? 如何向我的网站添加文字? - How can I add text to my website?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM