1
このプロジェクト全体に対して、ロードdivの表示/非表示を設定するハンドラをいくつか設定しました。ajaxStopの前に実行するフォーム提出ハンドラ
それらのいくつかはforms
にバインドされajaxStart
、ajaxStop
(両方とも$(document)
にバインドさ)とsubmit
です。
ajaxStop
が怒鳴る、試料中のform.submit
後に実行されている理由を私は理解できない:ajaxStop()
はすべてアクティブにcomplete
イベントが発生した後に呼び出されるため
var blobs = [];
var echo = function echo(data, type) {
var blob = window.URL.createObjectURL(new Blob([data], {
"type": type
}));
blobs.push(blob);
return blob
};
$(document).ready(function() {
$('form').on('submit', function(e) {
console.log('form submit');
e.preventDefault();
});
}).ajaxStart(function() {
console.log('ajaxStart');
}).ajaxStop(function() {
console.log('ajaxStop');
});
$('button').click(function() {
$.get(echo("Sample data", "text/html"), function(data) {
if (data != '')
$('#frm').submit();
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<form id="frm">
<button type="button">
Send
</button>
</form>
私は '.complete'や' .always'を使っていましたか? – Marco
違いはありません。 'ajaxStop()'はすべてのリクエストが完了した後に起動します。ここで注文を見ることができます:https://jsfiddle.net/872dmpxe/ –
いくつかのテスト(あなたを含む)を実行した後、私はシーケンスと私が何を変更しなければならないかを完全に理解しています。フォームにクラスが含まれていなければならないので、後に続く 'ajaxStop'でローダーを閉じないでください。ありがとう。 – Marco