Quote:
comment out the code:
$(document).keydown(function () { return false; });
That fixes the problem, though it does not explain it...
The problem is, you're not removing the event listener; you're simply adding another event listener.
You now have two listeners for the same event. One returns
false
; the other returns
true
. There's no guarantee which order these listeners will be executed in, and no way of combining the return value from both listeners.
Move your listener to a separate function. Then you can use
the off
method[
^] to remove the listener.
You can also move the
beforeSend
code immediately before the
ajax
call, and use the promise interface methods for the callbacks.
var preventKeyboard = function() { return false; };
$(document).keydown(preventKeyboard);
$(".overlay").show();
$('#loadingGIF').show();
$.ajax({
type: "POST",
url: "GC_UserErrors.aspx/receiveAJAXMessage",
data: sMsg1,
contentType: "application/json; charset=utf-8",
dataType: "json",
})
.done(OnSuccess)
.fail(OnFailure)
.always(function(){
$(document).off("keydown", preventKeyboard);
$(".overlay").hide();
$('#loadingGIF').hide();
$('#idtxtLoggingDaysDisplayed').prop('disabled', false);
});