How to eliminate the ajax that is still in progress after the react component is closed

I have a list. Clicking on the row will pop up the modal box , send ajax based on the information on each line, and display the results in the modal box .

however,
if I click on the first line to send the request, and there is no result, I close the modal box , and then I click on the second line, which sends the request again. If the ajax of the first line is stuck for a while, later than the second, then waiting for the first to finish, you should overwrite the result of the second. How to solve this problem.

Aug.09,2021

use ajax's abort method to block outstanding requests when the modal box can be closed according to description


make your request cancelable. The cancellation here is not a cancellation. Because the request has been sent, there is no way to terminate it.

the so-called cancel is actually canceling the callback function, and react has officially given a best practice.

  

unmount lifecycle abort calls ajax

Menu