好的,我設法解決了,基本上我創建了一個函數只是為了中止這樣的ajax請求:
this.abortAjax = () => {
requestHandler.abort();
}
然后使用預先實例化的 term 對象在 terminal.js 本身中訪問它。 在處理完代碼后,我能夠將所有內容保留在終端腳本中,而不是分成兩部分,得到如下內容:
function ShowLoadingScreen () {
var customElement = $("<div>", {
"class" : "btn btn-danger btn-lg",
"text" : "Abort",
"onclick": "term.abortAjax()"
});
$.LoadingOverlay("show", {
//image : "/static/loading.gif",
background : "rgba(204, 187, 0, 0.8)",
imageAnimation : "rotate_right",
//imageAutoResize : true,
text : "Loading...",
custom : customElement
});
}
function request (command) {
...
requestHandler = $.ajax({
url: _url,
beforeSend: function () { ShowLoadingScreen(); }, // <Show OverLay
type: 'GET',
dataType: 'json',
success: function (response) {
...
},
complete: function () { HideLoadingScreen(); } //<Hide Overlay
}).fail(function (jqXHR, textStatus, error) {
...
});
ShowLoadingScreen();
}
謝謝大家。