Permalink
Browse files

Merge branch 'redirect'

  • Loading branch information...
2 parents 8713d98 + 32e9034 commit 93f51d0cd5d33079143f79bac4c4667d3069cfe4 @josh josh committed Feb 22, 2012
Showing with 31 additions and 0 deletions.
  1. +6 −0 jquery.pjax.js
  2. +11 −0 test/app.rb
  3. +14 −0 test/unit/pjax.js
View
6 jquery.pjax.js
@@ -197,6 +197,9 @@ var pjax = $.pjax = function( options ) {
}
options.error = function(xhr, textStatus, errorThrown) {
+ var respUrl = xhr.getResponseHeader('X-PJAX-URL')
+ if (respUrl) url = stripPjaxParam(respUrl)
+
// DEPRECATED: Invoke original `error` handler
if (oldError) oldError.apply(this, arguments)
@@ -207,6 +210,9 @@ var pjax = $.pjax = function( options ) {
}
options.success = function(data, status, xhr) {
+ var respUrl = xhr.getResponseHeader('X-PJAX-URL')
+ if (respUrl) url = stripPjaxParam(respUrl)
+
var title, oldTitle = document.title
if ( options.fragment ) {
View
11 test/app.rb
@@ -19,6 +19,13 @@ def title(str)
end
end
+after do
+ if pjax?
+ response.headers['X-PJAX-URL'] = request.url
+ end
+end
+
+
get '/' do
erb :qunit
end
@@ -43,6 +50,10 @@ def title(str)
erb :env, :layout => !pjax?
end
+get '/redirect.html' do
+ redirect "/hello.html"
+end
+
get '/timeout.html' do
if pjax?
sleep 1
View
14 test/unit/pjax.js
@@ -574,4 +574,18 @@ if ($.support.pjax) {
}
})
})
+
+ asyncTest("follows redirect with X-PJAX-URL header", function() {
+ var frame = this.frame
+
+ frame.$.pjax({
+ url: "redirect.html",
+ container: "#main",
+ success: function() {
+ equal(frame.location.pathname, "/hello.html")
+ equal(frame.$("#main").html().trim(), "<p>Hello!</p>")
+ start()
+ }
+ })
+ })
}

0 comments on commit 93f51d0

Please sign in to comment.