【发布时间】:2019-10-16 10:58:30
【问题描述】:
我可以问一些关于 SPA 的概念吗? 我使用 SPA 开发了客户端网页。 在菜单 A 中单击它会请求一些 ajax 调用并等待响应。 在此期间,如果我转到另一个页面 B,A 的 ajax 响应来了,它试图调用已经加载的 javascript 代码,因为浏览器没有在 SPA 中执行刷新。 怎样才能避免这种情况,忽略之前A的所有ajax响应?
$.ajax({
url: url,
type: "GET",
dataType: "json",
headers: {"Authorization": 'Token ' + myToken},
success: function(response) {
my_callback(response); // <== I want to block this if leaves current page...
},
error: function(response) {
},
complete: function(response) {
}
});
【问题讨论】:
-
abort 请求。
标签: javascript jquery html single-page-application