how to schedule ajax calls every N seconds?

前端 未结 4 1485
天命终不由人
天命终不由人 2020-12-02 02:17

If I want a whole page to reload every N seconds, I would put something like this in the HTML: meta http-equiv=\"refresh\" content=\"5\"

Is there a sta

4条回答
  •  春和景丽
    2020-12-02 02:36

    You could use setTimeout or setInterval (the latter is probably best suited to what you want to do).

    setInterval(makeRequest, (10 * 1000));
    

    ...where makeRequest is a function that reloads some content via AJAX.

提交回复
热议问题