Skip to content

Instantly share code, notes, and snippets.

@olivernn
Created March 28, 2011 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olivernn/890536 to your computer and use it in GitHub Desktop.
Save olivernn/890536 to your computer and use it in GitHub Desktop.
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