How to make one function execute the next function after it is finished in js

clipboard.png
this is the code. When I click on the switch language section, I have to request a new English menu again.
getAgent () is the function for me to request the English menu, but there is still some data that must be refreshed to get
no matter I choose
window.location.reload (true);.
doesn"t work before or after getAgent (). I just want to refresh the page after the getAgent () function has been executed. Thank you

.
Mar.04,2021

  1. callback
  2. promise

getAgent () is a request method so you can use promise to do


es6 async function you deserve to have.


the simpler one: use callback.

let callback = () => { window.location.reload(true) };

getAgent(callback);

function getAgent(callback) {
  // ...
  callback();
}
Menu