Skip to content

Commit 2f0be19

Browse files
author
Daisuke Baba
committed
Abort the preceding request when it's no longer used
1 parent a82fb98 commit 2f0be19

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/generic-ble.html

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@
305305
return current ? toDeviceKey(current) : '';
306306
}
307307

308+
var lastBledevRequest = null;
308309
function applyBleDevice() {
309310
var selected = getBleDevice();
310311
if (!selected) {
@@ -320,11 +321,16 @@
320321
{style:'display:block; margin-left:auto; margin-right:auto;'})
321322
.appendTo($('#node-config-input-characteristics-container'));
322323

323-
$.ajax({
324+
if (lastBledevRequest) {
325+
lastBledevRequest.abort();
326+
lastBledevRequest = null;
327+
}
328+
lastBledevRequest = $.ajax({
324329
cache: false,
325330
url: '__bledev/' + encodeURIComponent(getUuid(selected)),
326331
dataType: 'json',
327332
success: function(bleDevice) {
333+
lastBledevRequest = null;
328334
spin.remove();
329335
if (getBleDeviceKey() === selectedId) {
330336
clearCharacteristics();
@@ -349,6 +355,7 @@
349355
}
350356
},
351357
error: function () {
358+
lastBledevRequest = null;
352359
spin.remove();
353360
if (getBleDeviceKey() === selectedId) {
354361
clearCharacteristics();

0 commit comments

Comments
 (0)