Have you ever encountered this when using XMLHttpRequest? The first time you use it, it works fine, but after refreshing it, it doesn’t work. After clearing the cache and refreshing it, it works again.
This is a problem often encountered when using XMLHttpRequest. Sometimes the results of the XMLHttpRequest request will be cached in the same URL. If the response after your request is different, some inexplicable problems will occur, including of course Haha at the beginning of the article.
Solution:
It’s simple once you know the principle, that is, the URL requested is different each time, so it makes a request to the server every time instead of using cache. Here are two commonly used methods:
The first method is to add a timestamp
var url = BaseURL "&timeStamp=" new Date().getTime();
The second method is to add a random number
var url = BaseURL "&r=" Math.random();
There may be many other methods, as long as you can ensure that It will be OK every time it goes to the server to request.