mirror of
https://github.com/bigskysoftware/htmx.git
synced 2025-10-02 07:21:05 +00:00
Merge pull request #225 from ChexWarrior/224-unlock-request-after-xhr-abort
End request lock when xmlHttpRequest is aborted awesome, thank you!
This commit is contained in:
commit
fa1db3b290
@ -2050,6 +2050,10 @@ return (function () {
|
||||
triggerErrorEvent(elt, 'htmx:sendError', eventDetail);
|
||||
endRequestLock();
|
||||
}
|
||||
xhr.onabort = function() {
|
||||
removeRequestIndicatorClasses(elt);
|
||||
endRequestLock();
|
||||
}
|
||||
if(!triggerEvent(elt, 'htmx:beforeRequest', eventDetail)) return endRequestLock();
|
||||
addRequestIndicatorClasses(elt);
|
||||
|
||||
|
@ -51,6 +51,9 @@
|
||||
<li>
|
||||
<a href="manual/sse-settle.html">SSE - Settling</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="manual/aborting-request.html">Aborting Request Test</a>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<h2>Mocha Test Suite</h2>
|
||||
|
36
test/manual/aborting-request.html
Normal file
36
test/manual/aborting-request.html
Normal file
@ -0,0 +1,36 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Aborting Request Event Test</title>
|
||||
</head>
|
||||
<body style="padding: 20px; font-family: sans-serif;">
|
||||
<h1>Aborting Request Event Tests</h1>
|
||||
<p>Aborting a request during an HTMX event should not prevent future events from firing.</p>
|
||||
<label for="block">Block Request?</label>
|
||||
<input id="block" type="checkbox" checked>
|
||||
<br><br>
|
||||
<button hx-get="https://httpbin.org/html"
|
||||
hx-target="#target">
|
||||
Send Request
|
||||
</button>
|
||||
<br><br>
|
||||
<h3>Event Messages:</h3>
|
||||
<div id="target"></div>
|
||||
<script src="../../src/htmx.js"></script>
|
||||
<script>
|
||||
var btn = document.querySelector('button');
|
||||
var checkbox = document.querySelector('input');
|
||||
var target = document.querySelector('#target');
|
||||
|
||||
btn.addEventListener('htmx:beforeRequest', function(e) {
|
||||
var messages = target.innerHTML;
|
||||
target.innerHTML = messages + "<p>Another Message!</p>";
|
||||
|
||||
if (checkbox.checked) {
|
||||
e.detail.xhr.abort();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Loading…
x
Reference in New Issue
Block a user