我每5分钟如何刷新带有api数据的表

时间:2019-07-10 15:09:39

标签: javascript jquery html

我正在做作业,我需要有关JavaScript的帮助。我的桌子上有货币,需要每2分钟刷新一次,并节省刷新时的时间。

我对javascript不太满意。我正在netbeans中创建此应用程序,我所知道的是我应该使用ajax和jquery。

这是我要在2分钟后刷新的div表

<div id="divLista">
    <table class="tM">
        <tr>
          <th class="tM-oznake">Valuta</th>
          <th class="tM-oznake">ISO</th>
          <th class="tM-oznake">OZN</th>
          <th class="tM-oznake">PAR</th>
          <th class="tM-oznake">KUPOVNI</th>
          <th class="tM-oznake">SREDNJI</th>
          <th class="tM-oznake">PRODAJNI</th>
        </tr>
        <tr>
          <td class="tM-valute">Američki dolar</td>
          <td class="tM-valute">USD</td>
          <td class="tM-valute">$</td>
          <td class="tM-valute">1</td>
          <td class="tM-valute">${currUsdK}</td>
          <td class="tM-valute">${currUsd}</td>
          <td class="tM-valute">${currUsdP}</td>
        </tr>
        <tr>
          <td class="tM-valute">Australijski dolar</td>
          <td class="tM-valute">AUD</td>
          <td class="tM-valute">$</td>
          <td class="tM-valute">1</td>
          <td class="tM-valute">${currAudK}</td>
          <td class="tM-valute">${currAud}</td>
          <td class="tM-valute">${currAudP}</td>
        </tr>
        <tr>
          <td class="tM-valute">BiH konvertibilna marka</td>
          <td class="tM-valute">BAM</td>
          <td class="tM-valute">KM</td>
          <td class="tM-valute">1</td>
          <td class="tM-valute">${currBamK}</td>
          <td class="tM-valute">${currBam}</td>
          <td class="tM-valute">${currBamP}</td>
        </tr>
        <tr>
          <td class="tM-valute">Britanska funta</td>
          <td class="tM-valute">GBP</td>
          <td class="tM-valute">£</td>
          <td class="tM-valute">1</td>
          <td class="tM-valute">${currGbpK}</td>
          <td class="tM-valute">${currGbp}</td>
          <td class="tM-valute">${currGbpP}</td>
        </tr>
        <tr>
          <td class="tM-valute">Hrvatska kuna</td>
          <td class="tM-valute">HRK</td>
          <td class="tM-valute">kn</td>
          <td class="tM-valute">1</td>
          <td class="tM-valute">${currHrkK}</td>
          <td class="tM-valute">${currHrk}</td>
          <td class="tM-valute">${currHrkP}</td>
        </tr>
        <tr>
          <td class="tM-valute">Japanski jen</td>
          <td class="tM-valute">JPY</td>
          <td class="tM-valute">¥</td>
          <td class="tM-valute">1</td>
          <td class="tM-valute">${currJpyK}</td>
          <td class="tM-valute">${currJpy}</td>
          <td class="tM-valute">${currJpyP}</td>
        </tr>
        <tr>
          <td class="tM-valute">Kanadski dolar</td>
          <td class="tM-valute">CAD</td>
          <td class="tM-valute">$</td>
          <td class="tM-valute">1</td>
          <td class="tM-valute">${currCadK}</td>
          <td class="tM-valute">${currCad}</td>
          <td class="tM-valute">${currCadP}</td>
        </tr>       
      </table>
      </div>

这是java spark设置,我正在使用API​​结果并将其打印在表中

port(5000);         
        get("/menjacnica", (request, response) -> {          
          Gson gson = new Gson();
          HashMap<String, Object> data = new HashMap<>();

这是应该节省时间的地方

<div id="divVreme">
        <table id="tVreme">
        <tr>
          <th id="datum"> Ažurirano : ${vreme}</th>
        </tr>
      </table>

它可以工作,但是每次刷新都会使新表得以修复,因此只能刷新表中的数据

     setInterval("refresh();", 5000);
   function refresh() {
   $('.tM').load('http://localhost:5000/menjacnica .tM');
   $('#vreme').load( '#vreme');
   console.log("azurirano");
   }

0 个答案:

没有答案