Last active
December 12, 2018 03:27
-
-
Save lizlux/808efdb185adb402449a48653463fc57 to your computer and use it in GitHub Desktop.
Testing window load with ajax call race condition
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<script | |
src="https://code.jquery.com/jquery-3.3.1.min.js" | |
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" | |
crossorigin="anonymous"></script> | |
</head> | |
<body> | |
<h1>Test race condition</h1> | |
<script> | |
console.log('start script'); | |
function init() { | |
console.log('init called'); | |
$(window).on('load', () => { | |
// doesn't get called (unless super fast connection) | |
console.log('window loaded from inside init'); | |
}); | |
} | |
$.get('https://data.sfgov.org/resource/wwmu-gmzc.json', () => { | |
console.log('got the response'); | |
init(); | |
}); | |
$(window).on('load', () => { | |
console.log('window loaded'); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment