About the problem that front-end ajax requests will be cached

Recently, when I was working on a javaweb project of the company, I needed to make a contact binding function, which is to simply convert the state value of a field between 0 and 1.
However, I encountered a very pitiful problem. When the user logs in, the status value is updated to 1, and after clicking the unbinding button, it prompts "unbinding succeeded", and the page jumps to the login page to view the database. Normally, the status value has been updated to 0, but after logging in again, the status value is also updated to 1. As a result, I click the unbind button, and it prompts "unbind successfully", but the page jumps to the home page, jump After going through the login page and viewing personal information, it is also fully displayed. Check the database again, the status value has not been updated.
After searching through various environments, I found that for the second and subsequent ajax requests, if the requested path is the same as the last time, the interface will not be re-requested, but the data of the last request will be returned directly. In other words, the second and subsequent requests did not enter the server, but returned by themselves at the front end. Therefore, an additional random parameter is added here, indicating that this is a new request, and ajax cannot be used to fetch data from the cache.
Generally speaking, a series of random numbers or the milliseconds of the current request time are used directly. It doesn't matter whether the added field is useful on the server side, it mainly tells ajax that this is a new request.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326372114&siteId=291194637