How to make sure that when you click on the button, the previous values ​​are deleted?

  • 0
    $.getJSON(uri + 'ExRates/Rates/Dynamics/' + valueCurrency[0], { 'startDate': parseRuDate($('#ifrom').val()).toUTCString(), 'endDate': parseRuDate($('#ito').val()).toUTCString() })
                  .done(function (data) {
                      $.each(data, function (key, item) {      
                          $('<th>',{ text: JSON.stringify(item['Date'].substr(0,10)) }).appendTo($('#res'));            
                          $('<td>',{ text: JSON.stringify(item['Cur_OfficialRate']) }).appendTo($('#usd'));
         <span id="Cur" style="display: none;">Cur_ID валюты: <input type="text" id="iCur" value="" /></span> 
        <span id="period">с: <input type="text" id="ifrom" /> по: <input type="text" id="ito" /></span>
        <input type="button" id="btn"  value="получить" />

    When clicked, data is loaded from the API and added to the table; on the next click, the old data that is added to the table remains, and at the same time new data is added. How to delete old data on click?
    Another problem, on line 5, how can you output the date from jsona without quotes?
    JavaScript Claire Mayer, Jun 9, 2020

  • 1 Answers
  • 0
    before adding data, you need to clear the content

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!