diff --git a/jquery.pjax.js b/jquery.pjax.js index 0a9cb1e1..2fb43d24 100644 --- a/jquery.pjax.js +++ b/jquery.pjax.js @@ -376,8 +376,12 @@ function pjaxReload(container, options) { // // Returns nothing. function locationReplace(url) { - window.history.replaceState(null, "", "#") - window.location.replace(url) + window.history.back() + setTimeout(function() { + window.history.replaceState(null, "", "#") + window.location.assign(url) + }, 0) + } diff --git a/test/app.rb b/test/app.rb index 9be09f53..4d75aaf7 100644 --- a/test/app.rb +++ b/test/app.rb @@ -78,6 +78,15 @@ def title(str) end end +get '/referer_timeout.html' do + if pjax? + sleep 1 + erb :referer, :layout => false + else + erb :referer + end +end + get '/boom.html' do status 500 erb :boom, :layout => !pjax? diff --git a/test/unit/pjax_fallback.js b/test/unit/pjax_fallback.js index 0ab5b032..9285af81 100644 --- a/test/unit/pjax_fallback.js +++ b/test/unit/pjax_fallback.js @@ -99,6 +99,21 @@ asyncTest("sends correct HTTP referer"+s, function() { }) }) +asyncTest("sends correct HTTP referer after failed request"+s, function() { + var frame = this.frame + + $('iframe')[0].onload = function() { + var referer = frame.document.getElementById("referer").textContent + equal(referer.substr(-10), "/home.html") + start() + } + + frame.$.pjax({ + url: "/referer_timeout.html", + container: "#main" + }) +}) + asyncTest("adds entry to browser history"+s, function() { var frame = this.frame var count = 0