Created
March 28, 2011 14:16
-
-
Save olivernn/890536 to your computer and use it in GitHub Desktop.
This file contains 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
require 'rubygems' | |
require 'sinatra' | |
get "/" do | |
erb :index | |
end | |
get "/slow_network" do | |
sleep(2) | |
"Done" | |
end | |
__END__ | |
@@index | |
<html> | |
<head> | |
</head> | |
<body> | |
<a id="link" href="/slow_network">Click Me</a> | |
<script type="text/javascript" charset="utf-8"> | |
var link = document.getElementById("link") | |
link.addEventListener("click", function (e) { | |
history.pushState({}, "", "/waiting") | |
var xhr = new XMLHttpRequest () | |
xhr.open("GET", "/slow_network") | |
xhr.onreadystatechange = function (event) { | |
if (xhr.readyState == 4) { | |
history.replaceState({}, "", "/blah") | |
alert("the url should have changed to '/blah'") | |
}; | |
} | |
xhr.send(null) | |
e.preventDefault() | |
}, true) | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment