Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

146
Views
¿Cómo implementar correctamente setInterval en la respuesta de la API en Javascript?

Obtengo la respuesta de API y agrego la respuesta en la tabla html. ahora estoy tratando de setInterval pero setInterval no está configurado correctamente. aquí está el código.

 const settings = { "async": true, "crossDomain": true, "url": "https://datasource.com/price?list", "method": "GET", "headers": { "xxxxxxxxxxxxxxxxxx", "xxxxxxxxxxxxxxxx" } }; setInterval(function() { $.ajax(settings).done(function(response) { var sdata = ''; $.each(response, function(key, value) { sdata += '<tr>'; sdata += '<td>' + value.symbol + '</td>'; sdata += '<td>' + value.lastPrice + '</td>'; sdata += '<td>' + value.change + '</td>'; sdata += '<td>' + value.pChange + '</td>'; sdata += '<td>' + value.open + '</td>'; sdata += '<td>' + value.dayHigh + '</td>'; sdata += '<td>' + value.dayLow + '</td>'; sdata += '<td>' + value.previousClose + '</td>'; sdata += '<td>' + value.perChange30d + '</td>'; sdata += '<td>' + value.perChange365d + '</td>'; sdata += '<td>' + value.lastUpdateTime + '</td>'; sdata += '</tr>'; }); $('#shares').html(sdata); //console.log(response); }); }, 5000);
 <table id="shares"> <tr> <th>NAME</th> <th>LTP</th> <th>CHANGE</th> <th>CHG %</th> <th>OPEN</th> <th>HIGH</th> <th>LOW</th> <th>CLOSE</th> <th>30 DAY ROI</th> <th>1 YR ROI</th> <th>UPDATED ON</th> </tr> </table>

¿Cómo puedo implementar un setInterval que funcione en el código javascript mencionado anteriormente?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

.append(sdata) agrega datos (como era de esperar :))

Si no desea agregar, sino reemplazar todo, use .html(sdata) .

violín actualizado

about 4 years ago · Juan Pablo Isaza Report

0

 const settings = { "async": true, "crossDomain": true, "url": "https://datasource.com/price?list", "method": "GET", "headers": { "xxxxxxxxxxxxxxxxxx", "xxxxxxxxxxxxxxxx" } }; setInterval(function() { $.ajax(settings).done(function (response) { var sdata = ''; $('#shares').empty(); $.each(response, function(key,value){ sdata += '<tr>'; sdata += '<td>'+value.symbol+'</td>'; sdata += '<td>'+value.lastPrice+'</td>'; sdata += '<td>'+value.change+'</td>'; sdata += '<td>'+value.pChange+'</td>'; sdata += '<td>'+value.open+'</td>'; sdata += '<td>'+value.dayHigh+'</td>'; sdata += '<td>'+value.dayLow+'</td>'; sdata += '<td>'+value.previousClose+'</td>'; sdata += '<td>'+value.perChange30d+'</td>'; sdata += '<td>'+value.perChange365d+'</td>'; sdata += '<td>'+value.lastUpdateTime+'</td>'; sdata += '</tr>'; }); $('#shares').html(sdata); }); }, 5000);
 table { border: 1px; }
 <!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <title></title> </head> <body> <table> <thead> <tr> <th>NAME</th> <th>LTP</th> <th>CHANGE</th> <th>CHG %</th> <th>OPEN</th> <th>HIGH</th> <th>LOW</th> <th>CLOSE</th> <th>30 DAY ROI</th> <th>1 YR ROI</th> <th>UPDATED ON</th> </tr> </thead> <tbody id="shares"> </tbody> </table>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!