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

126
Views
Why api can't refresh?

I am making a random color generator. When I refresh or click the generate button, the api gets the same result. But when I refresh the api site, the information changes randomly.

Here is the api site and the demo

const BASE_URL = 'https://www.colr.org/json/colors/random'
const colorCardsTotal = '5'
function getColors(){
  axios.get(BASE_URL+'/'+colorCardsTotal)
  .then(function (response) {
    console.log(response.data.colors)
  })
  .catch(function (error) {
    // 2.handle error
    console.log(error)
  })
}

getColors()
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>

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

0

This won't refresh new colors due to browser disk cache.

enter image description here

To fix it, you need to add timestamp to your request:

const BASE_URL = 'https://www.colr.org/json/colors/random'
const colorCardsTotal = '5'

function getColors() {
  axios.get(BASE_URL + '/' + colorCardsTotal, {
      params: {
        t: new Date().getTime()
      }
    })
    .then(function(response) {
      console.log(response.data.colors)
    })
    .catch(function(error) {
      // 2.handle error
      console.log(error)
    })
}

getColors()

And here's the edited based on your demo.

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!