Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/430.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在我的网站上自动更新以太坊价格_Javascript_Ajax_Ethereum - Fatal编程技术网

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

Javascript 如何在我的网站上自动更新以太坊价格,javascript,ajax,ethereum,Javascript,Ajax,Ethereum,我想在我的网站上显示etherum的最新价格,但不幸的是,如果不重新加载页面,它不会自动更新 <script> $.ajax({ url : 'https://api.coinmarketcap.com/v1/ticker/ethereum/', type : 'GET', data : { 'numberOfWords' : 10 }, dataType:'json', success : function(da

我想在我的网站上显示etherum的最新价格,但不幸的是,如果不重新加载页面,它不会自动更新

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

$.ajax({
网址:'https://api.coinmarketcap.com/v1/ticker/ethereum/',
键入:“GET”,
数据:{
“numberOfWords”:10
},
数据类型:'json',
成功:功能(数据){
eth_价格=数据[0]。价格为美元;
document.getElementById('eth_price')。innerHTML=eth_price;
},
错误:函数(请求、错误)
{
log(“获取ETH价格时出错”);
}
});
我如何解决这个问题,使最后的价格总是显示没有重新加载网站每次

我认为ajax默认是这样做的?

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