After switching the page, the ajax response of the previous page returned, but the error report of the page element could not be found. How to solve this problem?

for a single-page application, the current page issues an ajax request. Before the response is returned, the main page on the right side is switched when the menu is switched, and the ajax response of the previous page is returned. There are too many scenarios in which an error is reported because the elements of the page before the switch cannot be found. If it is troublesome to judge whether a page element exists or not in every request, solve the problem.
Thank you.

Feb.28,2021

add a judgment to determine whether this element exists


so when you get the ajax response, just judge whether the current page (route) has changed

.
Menu